Skip to content

Commit 51479d1

Browse files
committed
refactor: rename mock_function_factory to create_fake_function_obj for clarity
1 parent bfa9879 commit 51479d1

File tree

5 files changed

+64
-68
lines changed

5 files changed

+64
-68
lines changed

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
from pytest_simcore.helpers.typing_env import EnvVarsDict
2727
from pytest_simcore.helpers.webserver_login import LoggedUser, UserInfoDict
2828
from servicelib.rabbitmq import RabbitMQRPCClient
29-
from servicelib.rabbitmq.rpc_interfaces.webserver.functions import (
30-
functions_rpc_interface as functions_rpc,
31-
)
29+
from servicelib.rabbitmq.rpc_interfaces.webserver.v1.client import WebServerRpcClient
3230
from settings_library.rabbit import RabbitSettings
3331
from simcore_postgres_database.models.funcapi_api_access_rights_table import (
3432
funcapi_api_access_rights_table,
@@ -86,7 +84,7 @@ async def rpc_client(
8684

8785

8886
@pytest.fixture
89-
def mock_function_factory() -> Callable[[FunctionClass], Function]:
87+
def create_fake_function_obj() -> Callable[[FunctionClass], Function]:
9088
def _(function_class: FunctionClass) -> Function:
9189
if function_class == FunctionClass.PROJECT:
9290
return ProjectFunction(
@@ -152,23 +150,21 @@ async def user_without_function_api_access_rights(
152150
@pytest.fixture
153151
async def clean_functions(
154152
client: TestClient,
155-
rpc_client: RabbitMQRPCClient,
153+
webserver_rpc_client: WebServerRpcClient,
156154
logged_user: UserInfoDict,
157155
osparc_product_name: ProductName,
158156
) -> None:
159157
assert client.app
160158

161-
functions, _ = await functions_rpc.list_functions(
162-
rabbitmq_rpc_client=rpc_client,
159+
functions, _ = await webserver_rpc_client.functions.list_functions(
163160
pagination_limit=100,
164161
pagination_offset=0,
165162
user_id=logged_user["id"],
166163
product_name=osparc_product_name,
167164
)
168165
for function in functions:
169166
assert function.uid is not None
170-
await functions_rpc.delete_function(
171-
rabbitmq_rpc_client=rpc_client,
167+
await webserver_rpc_client.functions.delete_function(
172168
function_id=function.uid,
173169
user_id=logged_user["id"],
174170
product_name=osparc_product_name,
@@ -178,23 +174,23 @@ async def clean_functions(
178174
@pytest.fixture
179175
async def clean_function_job_collections(
180176
client: TestClient,
181-
rpc_client: RabbitMQRPCClient,
177+
webserver_rpc_client: WebServerRpcClient,
182178
logged_user: UserInfoDict,
183179
osparc_product_name: ProductName,
184180
) -> None:
185181
assert client.app
186182

187-
job_collections, _ = await functions_rpc.list_function_job_collections(
188-
rabbitmq_rpc_client=rpc_client,
189-
pagination_limit=100,
190-
pagination_offset=0,
191-
user_id=logged_user["id"],
192-
product_name=osparc_product_name,
183+
job_collections, _ = (
184+
await webserver_rpc_client.functions.list_function_job_collections(
185+
pagination_limit=100,
186+
pagination_offset=0,
187+
user_id=logged_user["id"],
188+
product_name=osparc_product_name,
189+
)
193190
)
194191
for function_job_collection in job_collections:
195192
assert function_job_collection.uid is not None
196-
await functions_rpc.delete_function_job_collection(
197-
rabbitmq_rpc_client=rpc_client,
193+
await webserver_rpc_client.functions.delete_function_job_collection(
198194
function_job_collection_id=function_job_collection.uid,
199195
user_id=logged_user["id"],
200196
product_name=osparc_product_name,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ async def test_set_and_remove_group_permissions(
2929
logged_user: UserInfoDict,
3030
other_logged_user: UserInfoDict,
3131
osparc_product_name: ProductName,
32-
mock_function_factory: Callable[[FunctionClass], RegisteredFunction],
32+
create_fake_function_obj: Callable[[FunctionClass], RegisteredFunction],
3333
clean_functions: None,
3434
) -> None:
3535
# Register the function
3636
registered_function = await _functions_service.register_function(
3737
app=client.app,
38-
function=mock_function_factory(FunctionClass.PROJECT),
38+
function=create_fake_function_obj(FunctionClass.PROJECT),
3939
user_id=logged_user["id"],
4040
product_name=osparc_product_name,
4141
)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
async def test_function_job_collection(
3939
client: TestClient,
4040
add_user_function_api_access_rights: None,
41-
mock_function_factory: Callable[[FunctionClass], Function],
41+
create_fake_function_obj: Callable[[FunctionClass], Function],
4242
webserver_rpc_client: WebServerRpcClient,
4343
logged_user: UserInfoDict,
4444
other_logged_user: UserInfoDict,
@@ -47,7 +47,7 @@ async def test_function_job_collection(
4747
):
4848
# Register the function first
4949
registered_function = await webserver_rpc_client.functions.register_function(
50-
function=mock_function_factory(FunctionClass.PROJECT),
50+
function=create_fake_function_obj(FunctionClass.PROJECT),
5151
user_id=logged_user["id"],
5252
product_name=osparc_product_name,
5353
)
@@ -166,7 +166,7 @@ async def test_function_job_collection(
166166
async def test_list_function_job_collections(
167167
client: TestClient,
168168
add_user_function_api_access_rights: None,
169-
mock_function_factory: Callable[[FunctionClass], Function],
169+
create_fake_function_obj: Callable[[FunctionClass], Function],
170170
webserver_rpc_client: WebServerRpcClient,
171171
clean_functions: None,
172172
clean_function_job_collections: None,
@@ -191,7 +191,7 @@ async def test_list_function_job_collections(
191191

192192
# Register the function first
193193
registered_function = await webserver_rpc_client.functions.register_function(
194-
function=mock_function_factory(FunctionClass.PROJECT),
194+
function=create_fake_function_obj(FunctionClass.PROJECT),
195195
user_id=logged_user["id"],
196196
product_name=osparc_product_name,
197197
)
@@ -269,20 +269,20 @@ async def test_list_function_job_collections_filtered_function_id(
269269
client: TestClient,
270270
add_user_function_api_access_rights: None,
271271
webserver_rpc_client: WebServerRpcClient,
272-
mock_function_factory: Callable[[FunctionClass], Function],
272+
create_fake_function_obj: Callable[[FunctionClass], Function],
273273
clean_functions: None,
274274
clean_function_job_collections: None,
275275
logged_user: UserInfoDict,
276276
osparc_product_name: ProductName,
277277
):
278278
# Register the function first
279279
registered_function = await webserver_rpc_client.functions.register_function(
280-
function=mock_function_factory(FunctionClass.PROJECT),
280+
function=create_fake_function_obj(FunctionClass.PROJECT),
281281
user_id=logged_user["id"],
282282
product_name=osparc_product_name,
283283
)
284284
other_registered_function = await webserver_rpc_client.functions.register_function(
285-
function=mock_function_factory(FunctionClass.PROJECT),
285+
function=create_fake_function_obj(FunctionClass.PROJECT),
286286
user_id=logged_user["id"],
287287
product_name=osparc_product_name,
288288
)

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ async def test_register_get_delete_function_job(
4949
client: TestClient,
5050
add_user_function_api_access_rights: None,
5151
webserver_rpc_client: WebServerRpcClient,
52-
mock_function_factory: Callable[[FunctionClass], Function],
52+
create_fake_function_obj: Callable[[FunctionClass], Function],
5353
logged_user: UserInfoDict,
5454
other_logged_user: UserInfoDict,
5555
osparc_product_name: ProductName,
5656
):
5757
# Register the function first
5858
registered_function = await webserver_rpc_client.functions.register_function(
59-
function=mock_function_factory(FunctionClass.PROJECT),
59+
function=create_fake_function_obj(FunctionClass.PROJECT),
6060
user_id=logged_user["id"],
6161
product_name=osparc_product_name,
6262
)
@@ -168,13 +168,13 @@ async def test_list_function_jobs(
168168
client: TestClient,
169169
add_user_function_api_access_rights: None,
170170
webserver_rpc_client: WebServerRpcClient,
171-
mock_function_factory: Callable[[FunctionClass], Function],
171+
create_fake_function_obj: Callable[[FunctionClass], Function],
172172
logged_user: UserInfoDict,
173173
osparc_product_name: ProductName,
174174
):
175175
# Register the function first
176176
registered_function = await webserver_rpc_client.functions.register_function(
177-
function=mock_function_factory(FunctionClass.PROJECT),
177+
function=create_fake_function_obj(FunctionClass.PROJECT),
178178
user_id=logged_user["id"],
179179
product_name=osparc_product_name,
180180
)
@@ -218,13 +218,13 @@ async def test_list_function_jobs_with_status(
218218
client: TestClient,
219219
add_user_function_api_access_rights: None,
220220
webserver_rpc_client: WebServerRpcClient,
221-
mock_function_factory: Callable[[FunctionClass], Function],
221+
create_fake_function_obj: Callable[[FunctionClass], Function],
222222
logged_user: UserInfoDict,
223223
osparc_product_name: ProductName,
224224
):
225225
# Register the function first
226226
registered_function = await webserver_rpc_client.functions.register_function(
227-
function=mock_function_factory(FunctionClass.PROJECT),
227+
function=create_fake_function_obj(FunctionClass.PROJECT),
228228
user_id=logged_user["id"],
229229
product_name=osparc_product_name,
230230
)
@@ -268,19 +268,19 @@ async def test_list_function_jobs_with_status(
268268
async def test_list_function_jobs_filtering(
269269
client: TestClient,
270270
webserver_rpc_client: WebServerRpcClient,
271-
mock_function_factory: Callable[[FunctionClass], Function],
271+
create_fake_function_obj: Callable[[FunctionClass], Function],
272272
logged_user: UserInfoDict,
273273
osparc_product_name: ProductName,
274274
add_user_function_api_access_rights: None,
275275
):
276276
# Register the function first
277277
first_registered_function = await webserver_rpc_client.functions.register_function(
278-
function=mock_function_factory(FunctionClass.PROJECT),
278+
function=create_fake_function_obj(FunctionClass.PROJECT),
279279
user_id=logged_user["id"],
280280
product_name=osparc_product_name,
281281
)
282282
second_registered_function = await webserver_rpc_client.functions.register_function(
283-
function=mock_function_factory(FunctionClass.PROJECT),
283+
function=create_fake_function_obj(FunctionClass.PROJECT),
284284
user_id=logged_user["id"],
285285
product_name=osparc_product_name,
286286
)
@@ -410,12 +410,12 @@ async def test_find_cached_function_jobs(
410410
logged_user: UserInfoDict,
411411
other_logged_user: UserInfoDict,
412412
osparc_product_name: ProductName,
413-
mock_function_factory: Callable[[FunctionClass], Function],
413+
create_fake_function_obj: Callable[[FunctionClass], Function],
414414
clean_functions: None,
415415
):
416416
# Register the function first
417417
registered_function = await webserver_rpc_client.functions.register_function(
418-
function=mock_function_factory(FunctionClass.PROJECT),
418+
function=create_fake_function_obj(FunctionClass.PROJECT),
419419
user_id=logged_user["id"],
420420
product_name=osparc_product_name,
421421
)
@@ -521,12 +521,12 @@ async def test_patch_registered_function_jobs(
521521
logged_user: UserInfoDict,
522522
other_logged_user: UserInfoDict,
523523
osparc_product_name: ProductName,
524-
mock_function_factory: Callable[[FunctionClass], Function],
524+
create_fake_function_obj: Callable[[FunctionClass], Function],
525525
clean_functions: None,
526526
function_job: RegisteredFunctionJob,
527527
patch: RegisteredFunctionJobPatch,
528528
):
529-
function = mock_function_factory(function_job.function_class)
529+
function = create_fake_function_obj(function_job.function_class)
530530

531531
registered_function = await webserver_rpc_client.functions.register_function(
532532
function=function,
@@ -597,12 +597,12 @@ async def test_incompatible_patch_model_error(
597597
logged_user: UserInfoDict,
598598
other_logged_user: UserInfoDict,
599599
osparc_product_name: ProductName,
600-
mock_function_factory: Callable[[FunctionClass], Function],
600+
create_fake_function_obj: Callable[[FunctionClass], Function],
601601
clean_functions: None,
602602
function_job: RegisteredFunctionJob,
603603
patch: RegisteredFunctionJobPatch,
604604
):
605-
function = mock_function_factory(function_job.function_class)
605+
function = create_fake_function_obj(function_job.function_class)
606606

607607
registered_function = await webserver_rpc_client.functions.register_function(
608608
function=function,
@@ -644,7 +644,7 @@ async def test_update_function_job_status_output(
644644
add_user_function_api_access_rights: None,
645645
logged_user: UserInfoDict,
646646
other_logged_user: UserInfoDict,
647-
mock_function_factory: Callable[[FunctionClass], Function],
647+
create_fake_function_obj: Callable[[FunctionClass], Function],
648648
osparc_product_name: ProductName,
649649
access_by_other_user: bool,
650650
check_write_permissions: bool,
@@ -653,7 +653,7 @@ async def test_update_function_job_status_output(
653653
):
654654
# Register the function first
655655
registered_function = await webserver_rpc_client.functions.register_function(
656-
function=mock_function_factory(FunctionClass.PROJECT),
656+
function=create_fake_function_obj(FunctionClass.PROJECT),
657657
user_id=logged_user["id"],
658658
product_name=osparc_product_name,
659659
)
@@ -738,12 +738,12 @@ async def test_update_function_job_outputs(
738738
webserver_rpc_client: WebServerRpcClient,
739739
add_user_function_api_access_rights: None,
740740
logged_user: UserInfoDict,
741-
mock_function_factory: Callable[[FunctionClass], Function],
741+
create_fake_function_obj: Callable[[FunctionClass], Function],
742742
osparc_product_name: ProductName,
743743
):
744744
# Register the function first
745745
registered_function = await webserver_rpc_client.functions.register_function(
746-
function=mock_function_factory(FunctionClass.PROJECT),
746+
function=create_fake_function_obj(FunctionClass.PROJECT),
747747
user_id=logged_user["id"],
748748
product_name=osparc_product_name,
749749
)

0 commit comments

Comments
 (0)