Skip to content

Commit 2b7026d

Browse files
adding unit tests
1 parent 551822d commit 2b7026d

File tree

1 file changed

+106
-4
lines changed

1 file changed

+106
-4
lines changed

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

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# pylint: disable=too-many-positional-arguments
88

99
from collections.abc import Awaitable, Callable
10-
from datetime import datetime, timezone
10+
from datetime import UTC, datetime, timedelta
1111
from typing import Any
1212

1313
from models_library.api_schemas_directorv2.comp_runs import (
@@ -66,7 +66,7 @@ async def test_rpc_list_computation_runs_and_tasks(
6666
user=user,
6767
project=proj,
6868
result=RunningState.PENDING,
69-
started=datetime.now(tz=timezone.utc),
69+
started=datetime.now(tz=UTC),
7070
iteration=2,
7171
)
7272
output = await rpc_computations.list_computations_latest_iteration_page(
@@ -82,8 +82,8 @@ async def test_rpc_list_computation_runs_and_tasks(
8282
user=user,
8383
project=proj,
8484
result=RunningState.SUCCESS,
85-
started=datetime.now(tz=timezone.utc),
86-
ended=datetime.now(tz=timezone.utc),
85+
started=datetime.now(tz=UTC),
86+
ended=datetime.now(tz=UTC),
8787
iteration=3,
8888
)
8989
output = await rpc_computations.list_computations_latest_iteration_page(
@@ -103,3 +103,105 @@ async def test_rpc_list_computation_runs_and_tasks(
103103
assert output.total == 4
104104
assert isinstance(output, ComputationTaskRpcGetPage)
105105
assert len(output.items) == 4
106+
107+
108+
async def test_rpc_list_computation_runs_with_filtering(
109+
fake_workbench_without_outputs: dict[str, Any],
110+
fake_workbench_adjacency: dict[str, Any],
111+
registered_user: Callable[..., dict[str, Any]],
112+
project: Callable[..., Awaitable[ProjectAtDB]],
113+
create_pipeline: Callable[..., Awaitable[CompPipelineAtDB]],
114+
create_tasks: Callable[..., Awaitable[list[CompTaskAtDB]]],
115+
create_comp_run: Callable[..., Awaitable[CompRunsAtDB]],
116+
rpc_client: RabbitMQRPCClient,
117+
):
118+
user = registered_user()
119+
120+
proj_1 = await project(user, workbench=fake_workbench_without_outputs)
121+
await create_pipeline(
122+
project_id=f"{proj_1.uuid}",
123+
dag_adjacency_list=fake_workbench_adjacency,
124+
)
125+
comp_tasks = await create_tasks(
126+
user=user, project=proj_1, state=StateType.PUBLISHED, progress=None
127+
)
128+
comp_runs = await create_comp_run(
129+
user=user, project=proj_1, result=RunningState.PUBLISHED
130+
)
131+
132+
proj_2 = await project(user, workbench=fake_workbench_without_outputs)
133+
await create_pipeline(
134+
project_id=f"{proj_2.uuid}",
135+
dag_adjacency_list=fake_workbench_adjacency,
136+
)
137+
comp_tasks = await create_tasks(
138+
user=user, project=proj_2, state=StateType.SUCCESS, progress=None
139+
)
140+
comp_runs = await create_comp_run(
141+
user=user, project=proj_2, result=RunningState.SUCCESS
142+
)
143+
144+
# Test default behaviour `filter_only_running=False`
145+
output = await rpc_computations.list_computations_latest_iteration_page(
146+
rpc_client, product_name="osparc", user_id=user["id"]
147+
)
148+
assert output.total == 2
149+
150+
# Test filtering
151+
output = await rpc_computations.list_computations_latest_iteration_page(
152+
rpc_client, product_name="osparc", user_id=user["id"], filter_only_running=True
153+
)
154+
assert output.total == 1
155+
assert output.items[0].project_uuid == proj_1.uuid
156+
157+
158+
async def test_rpc_list_computation_runs_history(
159+
fake_workbench_without_outputs: dict[str, Any],
160+
fake_workbench_adjacency: dict[str, Any],
161+
registered_user: Callable[..., dict[str, Any]],
162+
project: Callable[..., Awaitable[ProjectAtDB]],
163+
create_pipeline: Callable[..., Awaitable[CompPipelineAtDB]],
164+
create_tasks: Callable[..., Awaitable[list[CompTaskAtDB]]],
165+
create_comp_run: Callable[..., Awaitable[CompRunsAtDB]],
166+
rpc_client: RabbitMQRPCClient,
167+
):
168+
user = registered_user()
169+
170+
proj = await project(user, workbench=fake_workbench_without_outputs)
171+
await create_pipeline(
172+
project_id=f"{proj.uuid}",
173+
dag_adjacency_list=fake_workbench_adjacency,
174+
)
175+
comp_tasks = await create_tasks(
176+
user=user, project=proj, state=StateType.PUBLISHED, progress=None
177+
)
178+
comp_runs_1 = await create_comp_run(
179+
user=user,
180+
project=proj,
181+
result=RunningState.SUCCESS,
182+
started=datetime.now(tz=UTC) - timedelta(minutes=120),
183+
ended=datetime.now(tz=UTC) - timedelta(minutes=100),
184+
iteration=1,
185+
)
186+
comp_runs_2 = await create_comp_run(
187+
user=user,
188+
project=proj,
189+
result=RunningState.SUCCESS,
190+
started=datetime.now(tz=UTC) - timedelta(minutes=90),
191+
ended=datetime.now(tz=UTC) - timedelta(minutes=60),
192+
iteration=2,
193+
)
194+
comp_runs_3 = await create_comp_run(
195+
user=user,
196+
project=proj,
197+
result=RunningState.FAILED,
198+
started=datetime.now(tz=UTC) - timedelta(minutes=50),
199+
ended=datetime.now(tz=UTC),
200+
iteration=3,
201+
)
202+
203+
output = await rpc_computations.list_computations_iterations_page(
204+
rpc_client, product_name="osparc", user_id=user["id"], project_id=proj.uuid
205+
)
206+
assert output.total == 3
207+
assert isinstance(output, ComputationRunRpcGetPage)

0 commit comments

Comments
 (0)