Skip to content

Commit 3a2f201

Browse files
committed
test fixes
1 parent 71ee6c3 commit 3a2f201

File tree

6 files changed

+125
-79
lines changed

6 files changed

+125
-79
lines changed

services/web/server/src/simcore_service_webserver/functions/_functions_service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ async def find_cached_function_jobs(
404404
project_job_id=returned_function_job.class_specific_data[
405405
"project_job_id"
406406
],
407+
job_creation_task_id=returned_function_job.class_specific_data.get(
408+
"job_creation_task_id"
409+
),
407410
created_at=returned_function_job.created,
408411
)
409412
)
@@ -416,9 +419,12 @@ async def find_cached_function_jobs(
416419
function_uid=returned_function_job.function_uuid,
417420
inputs=returned_function_job.inputs,
418421
outputs=None,
419-
solver_job_id=returned_function_job.class_specific_data[
422+
solver_job_id=returned_function_job.class_specific_data.get(
420423
"solver_job_id"
421-
],
424+
),
425+
job_creation_task_id=returned_function_job.class_specific_data.get(
426+
"job_creation_task_id"
427+
),
422428
created_at=returned_function_job.created,
423429
)
424430
)

services/web/server/tests/unit/with_dbs/04/functions/conftest.py

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
JSONFunctionOutputSchema,
1818
ProjectFunction,
1919
)
20+
from models_library.functions import FunctionClass, SolverFunction
2021
from models_library.products import ProductName
2122
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
2223
from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan
@@ -69,25 +70,53 @@ async def rpc_client(
6970

7071

7172
@pytest.fixture
72-
def mock_function() -> Function:
73-
return ProjectFunction(
74-
title="Test Function",
75-
description="A test function",
76-
input_schema=JSONFunctionInputSchema(
77-
schema_content={
78-
"type": "object",
79-
"properties": {"input1": {"type": "string"}},
80-
}
81-
),
82-
output_schema=JSONFunctionOutputSchema(
83-
schema_content={
84-
"type": "object",
85-
"properties": {"output1": {"type": "string"}},
86-
}
87-
),
88-
project_id=uuid4(),
89-
default_inputs=None,
90-
)
73+
def mock_function_factory() -> Callable[[FunctionClass], Function]:
74+
75+
def _(function_class: FunctionClass) -> Function:
76+
if function_class == FunctionClass.PROJECT:
77+
return ProjectFunction(
78+
title="Test Function",
79+
description="A test function",
80+
input_schema=JSONFunctionInputSchema(
81+
schema_content={
82+
"type": "object",
83+
"properties": {"input1": {"type": "string"}},
84+
}
85+
),
86+
output_schema=JSONFunctionOutputSchema(
87+
schema_content={
88+
"type": "object",
89+
"properties": {"output1": {"type": "string"}},
90+
}
91+
),
92+
project_id=uuid4(),
93+
default_inputs=None,
94+
)
95+
if function_class == FunctionClass.SOLVER:
96+
return SolverFunction(
97+
title="Test Solver",
98+
description="A test solver",
99+
input_schema=JSONFunctionInputSchema(
100+
schema_content={
101+
"type": "object",
102+
"properties": {"input1": {"type": "string"}},
103+
}
104+
),
105+
output_schema=JSONFunctionOutputSchema(
106+
schema_content={
107+
"type": "object",
108+
"properties": {"output1": {"type": "string"}},
109+
}
110+
),
111+
default_inputs=None,
112+
solver_key="simcore/services/comp/mysolver",
113+
solver_version="1.0.0",
114+
)
115+
raise AssertionError(
116+
f"Please implement the mock for {function_class=} yourself"
117+
)
118+
119+
return _
91120

92121

93122
@pytest.fixture

services/web/server/tests/unit/with_dbs/04/functions/test_function_job_collections_controller_rpc.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# pylint: disable=unused-argument
33

44
import datetime
5+
from collections.abc import Callable
56
from uuid import uuid4
67

78
import pytest
@@ -10,10 +11,13 @@
1011
from models_library.api_schemas_webserver.functions import (
1112
FunctionIDString,
1213
FunctionJobCollection,
13-
ProjectFunction,
1414
ProjectFunctionJob,
1515
)
16-
from models_library.functions import FunctionJobCollectionsListFilters
16+
from models_library.functions import (
17+
Function,
18+
FunctionClass,
19+
FunctionJobCollectionsListFilters,
20+
)
1721
from models_library.functions_errors import (
1822
FunctionJobCollectionReadAccessDeniedError,
1923
FunctionJobCollectionsReadApiAccessDeniedError,
@@ -37,7 +41,7 @@
3741
async def test_function_job_collection(
3842
client: TestClient,
3943
add_user_function_api_access_rights: None,
40-
mock_function: ProjectFunction,
44+
mock_function_factory: Callable[[FunctionClass], Function],
4145
rpc_client: RabbitMQRPCClient,
4246
logged_user: UserInfoDict,
4347
other_logged_user: UserInfoDict,
@@ -47,7 +51,7 @@ async def test_function_job_collection(
4751
# Register the function first
4852
registered_function = await functions_rpc.register_function(
4953
rabbitmq_rpc_client=rpc_client,
50-
function=mock_function,
54+
function=mock_function_factory(FunctionClass.PROJECT),
5155
user_id=logged_user["id"],
5256
product_name=osparc_product_name,
5357
)
@@ -171,7 +175,7 @@ async def test_function_job_collection(
171175
async def test_list_function_job_collections(
172176
client: TestClient,
173177
add_user_function_api_access_rights: None,
174-
mock_function: ProjectFunction,
178+
mock_function_factory: Callable[[FunctionClass], Function],
175179
rpc_client: RabbitMQRPCClient,
176180
clean_functions: None,
177181
clean_function_job_collections: None,
@@ -196,7 +200,7 @@ async def test_list_function_job_collections(
196200
# Register the function first
197201
registered_function = await functions_rpc.register_function(
198202
rabbitmq_rpc_client=rpc_client,
199-
function=mock_function,
203+
function=mock_function_factory(FunctionClass.PROJECT),
200204
user_id=logged_user["id"],
201205
product_name=osparc_product_name,
202206
)
@@ -275,7 +279,7 @@ async def test_list_function_job_collections_filtered_function_id(
275279
client: TestClient,
276280
add_user_function_api_access_rights: None,
277281
rpc_client: RabbitMQRPCClient,
278-
mock_function: ProjectFunction,
282+
mock_function_factory: Callable[[FunctionClass], Function],
279283
clean_functions: None,
280284
clean_function_job_collections: None,
281285
logged_user: UserInfoDict,
@@ -284,13 +288,13 @@ async def test_list_function_job_collections_filtered_function_id(
284288
# Register the function first
285289
registered_function = await functions_rpc.register_function(
286290
rabbitmq_rpc_client=rpc_client,
287-
function=mock_function,
291+
function=mock_function_factory(FunctionClass.PROJECT),
288292
user_id=logged_user["id"],
289293
product_name=osparc_product_name,
290294
)
291295
other_registered_function = await functions_rpc.register_function(
292296
rabbitmq_rpc_client=rpc_client,
293-
function=mock_function,
297+
function=mock_function_factory(FunctionClass.PROJECT),
294298
user_id=logged_user["id"],
295299
product_name=osparc_product_name,
296300
)

services/web/server/tests/unit/with_dbs/04/functions/test_function_jobs_controller_rpc.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
# pylint: disable=unused-argument
33

44
import datetime
5+
from collections.abc import Callable
56
from uuid import uuid4
67

78
import pytest
89
from aiohttp.test_utils import TestClient
910
from common_library.users_enums import UserRole
1011
from faker import Faker
1112
from models_library.api_schemas_webserver.functions import (
12-
ProjectFunction,
1313
ProjectFunctionJob,
1414
)
1515
from models_library.functions import (
16+
Function,
1617
FunctionClass,
1718
FunctionJobCollection,
1819
FunctionJobStatus,
@@ -47,15 +48,15 @@ async def test_register_get_delete_function_job(
4748
client: TestClient,
4849
add_user_function_api_access_rights: None,
4950
rpc_client: RabbitMQRPCClient,
50-
mock_function: ProjectFunction,
51+
mock_function_factory: Callable[[FunctionClass], Function],
5152
logged_user: UserInfoDict,
5253
other_logged_user: UserInfoDict,
5354
osparc_product_name: ProductName,
5455
):
5556
# Register the function first
5657
registered_function = await functions_rpc.register_function(
5758
rabbitmq_rpc_client=rpc_client,
58-
function=mock_function,
59+
function=mock_function_factory(FunctionClass.PROJECT),
5960
user_id=logged_user["id"],
6061
product_name=osparc_product_name,
6162
)
@@ -175,14 +176,14 @@ async def test_list_function_jobs(
175176
client: TestClient,
176177
add_user_function_api_access_rights: None,
177178
rpc_client: RabbitMQRPCClient,
178-
mock_function: ProjectFunction,
179+
mock_function_factory: Callable[[FunctionClass], Function],
179180
logged_user: UserInfoDict,
180181
osparc_product_name: ProductName,
181182
):
182183
# Register the function first
183184
registered_function = await functions_rpc.register_function(
184185
rabbitmq_rpc_client=rpc_client,
185-
function=mock_function,
186+
function=mock_function_factory(FunctionClass.PROJECT),
186187
user_id=logged_user["id"],
187188
product_name=osparc_product_name,
188189
)
@@ -227,21 +228,21 @@ async def test_list_function_jobs(
227228
async def test_list_function_jobs_filtering(
228229
client: TestClient,
229230
rpc_client: RabbitMQRPCClient,
230-
mock_function: ProjectFunction,
231+
mock_function_factory: Callable[[FunctionClass], Function],
231232
logged_user: UserInfoDict,
232233
osparc_product_name: ProductName,
233234
add_user_function_api_access_rights: None,
234235
):
235236
# Register the function first
236237
first_registered_function = await functions_rpc.register_function(
237238
rabbitmq_rpc_client=rpc_client,
238-
function=mock_function,
239+
function=mock_function_factory(FunctionClass.PROJECT),
239240
user_id=logged_user["id"],
240241
product_name=osparc_product_name,
241242
)
242243
second_registered_function = await functions_rpc.register_function(
243244
rabbitmq_rpc_client=rpc_client,
244-
function=mock_function,
245+
function=mock_function_factory(FunctionClass.PROJECT),
245246
user_id=logged_user["id"],
246247
product_name=osparc_product_name,
247248
)
@@ -376,13 +377,13 @@ async def test_find_cached_function_jobs(
376377
logged_user: UserInfoDict,
377378
other_logged_user: UserInfoDict,
378379
osparc_product_name: ProductName,
379-
mock_function: ProjectFunction,
380+
mock_function_factory: Callable[[FunctionClass], Function],
380381
clean_functions: None,
381382
):
382383
# Register the function first
383384
registered_function = await functions_rpc.register_function(
384385
rabbitmq_rpc_client=rpc_client,
385-
function=mock_function,
386+
function=mock_function_factory(FunctionClass.PROJECT),
386387
user_id=logged_user["id"],
387388
product_name=osparc_product_name,
388389
)
@@ -448,13 +449,13 @@ async def test_patch_registered_function_jobs(
448449
logged_user: UserInfoDict,
449450
other_logged_user: UserInfoDict,
450451
osparc_product_name: ProductName,
451-
mock_function: ProjectFunction,
452+
mock_function_factory: Callable[[FunctionClass], Function],
452453
clean_functions: None,
453454
):
454455

455456
registered_function = await functions_rpc.register_function(
456457
rabbitmq_rpc_client=rpc_client,
457-
function=mock_function,
458+
function=mock_function_factory(FunctionClass.PROJECT),
458459
user_id=logged_user["id"],
459460
product_name=osparc_product_name,
460461
)
@@ -511,13 +512,13 @@ async def test_update_function_job_status(
511512
rpc_client: RabbitMQRPCClient,
512513
add_user_function_api_access_rights: None,
513514
logged_user: UserInfoDict,
514-
mock_function: ProjectFunction,
515+
mock_function_factory: Callable[[FunctionClass], Function],
515516
osparc_product_name: ProductName,
516517
):
517518
# Register the function first
518519
registered_function = await functions_rpc.register_function(
519520
rabbitmq_rpc_client=rpc_client,
520-
function=mock_function,
521+
function=mock_function_factory(FunctionClass.PROJECT),
521522
user_id=logged_user["id"],
522523
product_name=osparc_product_name,
523524
)
@@ -571,13 +572,13 @@ async def test_update_function_job_outputs(
571572
rpc_client: RabbitMQRPCClient,
572573
add_user_function_api_access_rights: None,
573574
logged_user: UserInfoDict,
574-
mock_function: ProjectFunction,
575+
mock_function_factory: Callable[[FunctionClass], Function],
575576
osparc_product_name: ProductName,
576577
):
577578
# Register the function first
578579
registered_function = await functions_rpc.register_function(
579580
rabbitmq_rpc_client=rpc_client,
580-
function=mock_function,
581+
function=mock_function_factory(FunctionClass.PROJECT),
581582
user_id=logged_user["id"],
582583
product_name=osparc_product_name,
583584
)

0 commit comments

Comments
 (0)