Skip to content

Commit 564efd1

Browse files
committed
repository almost tested
1 parent ea29f63 commit 564efd1

File tree

3 files changed

+97
-16
lines changed

3 files changed

+97
-16
lines changed

services/director-v2/src/simcore_service_director_v2/core/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class ConfigurationError(DirectorError):
3535
msg_template: str = "Application misconfiguration: {msg}"
3636

3737

38+
class UserNotFoundError(DirectorError):
39+
msg_template: str = "user {user_id} not found"
40+
41+
3842
class ProjectNotFoundError(DirectorError):
3943
msg_template: str = "project {project_id} not found"
4044

services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
from sqlalchemy.sql.elements import literal_column
1717
from sqlalchemy.sql.expression import desc
1818

19-
from ....core.errors import ClusterNotFoundError, ComputationalRunNotFoundError
19+
from ....core.errors import (
20+
ClusterNotFoundError,
21+
ComputationalRunNotFoundError,
22+
DirectorError,
23+
ProjectNotFoundError,
24+
UserNotFoundError,
25+
)
2026
from ....models.comp_runs import CompRunsAtDB, RunMetadataDict
2127
from ....utils.db import RUNNING_STATE_TO_DB
2228
from ..tables import comp_runs
@@ -136,7 +142,16 @@ async def create(
136142
row = await result.first()
137143
return CompRunsAtDB.model_validate(row)
138144
except ForeignKeyViolation as exc:
139-
raise ClusterNotFoundError(cluster_id=cluster_id) from exc
145+
message = exc.args[0]
146+
match message:
147+
case s if "users" in s and "user_id" in s:
148+
raise UserNotFoundError(user_id=user_id) from exc
149+
case s if "projects" in s and "project_uuid" in s:
150+
raise ProjectNotFoundError(project_id=project_id) from exc
151+
case s if "clusters" in s and "cluster_id" in s:
152+
raise ClusterNotFoundError(cluster_id=cluster_id) from exc
153+
case _:
154+
raise DirectorError from exc
140155

141156
async def update(
142157
self, user_id: UserID, project_id: ProjectID, iteration: PositiveInt, **values

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_db_repositories_comp_runs.py

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
# pylint: disable=unused-argument
66
# pylint: disable=unused-variable
77

8-
from typing import Awaitable, Callable
8+
from collections.abc import Awaitable, Callable
99

1010
import pytest
1111
from _helpers import PublishedProject
1212
from faker import Faker
13+
from models_library.clusters import DEFAULT_CLUSTER_ID, Cluster
1314
from models_library.projects import ProjectID
1415
from models_library.users import UserID
15-
from simcore_service_director_v2.core.errors import ComputationalRunNotFoundError
16-
from simcore_service_director_v2.models.comp_runs import CompRunsAtDB
16+
from simcore_service_director_v2.core.errors import (
17+
ClusterNotFoundError,
18+
ComputationalRunNotFoundError,
19+
ProjectNotFoundError,
20+
UserNotFoundError,
21+
)
22+
from simcore_service_director_v2.models.comp_runs import CompRunsAtDB, RunMetadataDict
1723
from simcore_service_director_v2.modules.db.repositories.comp_runs import (
1824
CompRunsRepository,
1925
)
@@ -54,39 +60,95 @@ async def test_get(
5460
published_project.project.prj_owner, published_project.project.uuid
5561
)
5662

57-
comp_run = await create_comp_run(published_project.user, published_project.project)
63+
await create_comp_run(published_project.user, published_project.project)
5864
await CompRunsRepository(aiopg_engine).get(
5965
published_project.project.prj_owner, published_project.project.uuid
6066
)
6167

6268

63-
async def test_list():
64-
...
69+
async def test_list(
70+
aiopg_engine,
71+
):
72+
assert await CompRunsRepository(aiopg_engine).list() == []
6573

6674

67-
async def test_create():
68-
...
75+
async def test_create(
76+
aiopg_engine,
77+
fake_user_id: UserID,
78+
fake_project_id: ProjectID,
79+
run_metadata: RunMetadataDict,
80+
faker: Faker,
81+
publish_project: Callable[[], Awaitable[PublishedProject]],
82+
create_cluster: Callable[..., Awaitable[Cluster]],
83+
):
84+
with pytest.raises(ProjectNotFoundError):
85+
await CompRunsRepository(aiopg_engine).create(
86+
user_id=fake_user_id,
87+
project_id=fake_project_id,
88+
cluster_id=DEFAULT_CLUSTER_ID,
89+
iteration=None,
90+
metadata=run_metadata,
91+
use_on_demand_clusters=faker.pybool(),
92+
)
93+
published_project = await publish_project()
94+
with pytest.raises(UserNotFoundError):
95+
await CompRunsRepository(aiopg_engine).create(
96+
user_id=fake_user_id,
97+
project_id=published_project.project.uuid,
98+
cluster_id=DEFAULT_CLUSTER_ID,
99+
iteration=None,
100+
metadata=run_metadata,
101+
use_on_demand_clusters=faker.pybool(),
102+
)
103+
104+
await CompRunsRepository(aiopg_engine).create(
105+
user_id=published_project.user["id"],
106+
project_id=published_project.project.uuid,
107+
cluster_id=DEFAULT_CLUSTER_ID,
108+
iteration=None,
109+
metadata=run_metadata,
110+
use_on_demand_clusters=faker.pybool(),
111+
)
112+
113+
with pytest.raises(ClusterNotFoundError):
114+
await CompRunsRepository(aiopg_engine).create(
115+
user_id=published_project.user["id"],
116+
project_id=published_project.project.uuid,
117+
cluster_id=faker.pyint(min_value=1),
118+
iteration=None,
119+
metadata=run_metadata,
120+
use_on_demand_clusters=faker.pybool(),
121+
)
122+
cluster = await create_cluster(published_project.user)
123+
await CompRunsRepository(aiopg_engine).create(
124+
user_id=published_project.user["id"],
125+
project_id=published_project.project.uuid,
126+
cluster_id=cluster.id,
127+
iteration=None,
128+
metadata=run_metadata,
129+
use_on_demand_clusters=faker.pybool(),
130+
)
69131

70132

71-
async def test_update():
133+
async def test_update(aiopg_engine):
72134
...
73135

74136

75-
async def test_delete():
137+
async def test_delete(aiopg_engine):
76138
...
77139

78140

79-
async def test_set_run_result():
141+
async def test_set_run_result(aiopg_engine):
80142
...
81143

82144

83-
async def test_mark_for_cancellation():
145+
async def test_mark_for_cancellation(aiopg_engine):
84146
...
85147

86148

87-
async def test_mark_for_scheduling():
149+
async def test_mark_for_scheduling(aiopg_engine):
88150
...
89151

90152

91-
async def test_mark_scheduling_done():
153+
async def test_mark_scheduling_done(aiopg_engine):
92154
...

0 commit comments

Comments
 (0)