Skip to content

Commit ae17e2c

Browse files
committed
check computation gets resources correctly
1 parent 7a8788a commit ae17e2c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

packages/pytest-simcore/src/pytest_simcore/db_entries_mocks.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ async def project(
6666
) -> AsyncIterator[Callable[..., Awaitable[ProjectAtDB]]]:
6767
created_project_ids: list[str] = []
6868

69-
async def creator(user: dict[str, Any], **project_overrides) -> ProjectAtDB:
69+
async def creator(
70+
user: dict[str, Any],
71+
*,
72+
project_nodes_overrides: dict[str, Any] | None = None,
73+
**project_overrides,
74+
) -> ProjectAtDB:
7075
project_uuid = uuid4()
7176
print(f"Created new project with uuid={project_uuid}")
7277
project_config = {
@@ -90,10 +95,13 @@ async def creator(user: dict[str, Any], **project_overrides) -> ProjectAtDB:
9095
inserted_project = ProjectAtDB.from_orm(await result.first())
9196
project_nodes_repo = ProjectNodesRepo(project_uuid=project_uuid)
9297
# NOTE: currently no resources is passed until it becomes necessary
98+
default_node_config = {"required_resources": {}}
99+
if project_nodes_overrides:
100+
default_node_config.update(project_nodes_overrides)
93101
await project_nodes_repo.add(
94102
con,
95103
nodes=[
96-
ProjectNodeCreate(node_id=NodeID(node_id))
104+
ProjectNodeCreate(node_id=NodeID(node_id), **default_node_config)
97105
for node_id in inserted_project.workbench
98106
],
99107
)

services/director-v2/tests/unit/with_dbs/test_api_route_computations.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,49 @@ async def test_start_computation(
301301
),
302302
)
303303
assert response.status_code == status.HTTP_201_CREATED, response.text
304+
mocked_get_service_resources = mocked_catalog_service_fcts["get_service_resources"]
305+
# there should be as many calls to the catalog as there are no defined resources by default
306+
assert mocked_get_service_resources.call_count == len(
307+
fake_workbench_without_outputs
308+
)
309+
310+
311+
async def test_start_computation_with_project_node_resources_defined(
312+
minimal_configuration: None,
313+
mocked_director_service_fcts,
314+
mocked_catalog_service_fcts,
315+
product_name: str,
316+
fake_workbench_without_outputs: dict[str, Any],
317+
registered_user: Callable[..., dict[str, Any]],
318+
project: Callable[..., Awaitable[ProjectAtDB]],
319+
async_client: httpx.AsyncClient,
320+
):
321+
user = registered_user()
322+
proj = await project(
323+
user,
324+
project_nodes_overrides={
325+
"required_resources": ServiceResourcesDictHelpers.Config.schema_extra[
326+
"examples"
327+
][0]
328+
},
329+
workbench=fake_workbench_without_outputs,
330+
)
331+
create_computation_url = httpx.URL("/v2/computations")
332+
response = await async_client.post(
333+
create_computation_url,
334+
json=jsonable_encoder(
335+
ComputationCreate(
336+
user_id=user["id"],
337+
project_id=proj.uuid,
338+
start_pipeline=True,
339+
product_name=product_name,
340+
)
341+
),
342+
)
343+
assert response.status_code == status.HTTP_201_CREATED, response.text
344+
mocked_get_service_resources = mocked_catalog_service_fcts["get_service_resources"]
345+
# there should be no calls to the catalog as there are resources defined, so no need to call the catalog
346+
assert mocked_get_service_resources.call_count == 0
304347

305348

306349
async def test_start_computation_with_deprecated_services_raises_406(

0 commit comments

Comments
 (0)