Skip to content

Commit f210702

Browse files
committed
Add test for function class filtering
1 parent 3bcf7d7 commit f210702

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

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

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
ProjectFunction,
1414
)
1515
from models_library.basic_types import IDStr
16-
from models_library.functions import FunctionUserAccessRights
16+
from models_library.functions import (
17+
FunctionClass,
18+
FunctionUserAccessRights,
19+
SolverFunction,
20+
)
1721
from models_library.functions_errors import (
1822
FunctionIDNotFoundError,
1923
FunctionReadAccessDeniedError,
@@ -422,6 +426,76 @@ async def test_list_functions_search(
422426
]
423427

424428

429+
@pytest.mark.parametrize(
430+
"user_role",
431+
[UserRole.USER],
432+
)
433+
async def test_list_functions_with_filters(
434+
client: TestClient,
435+
rpc_client: RabbitMQRPCClient,
436+
mock_function: ProjectFunction,
437+
logged_user: UserInfoDict,
438+
osparc_product_name: ProductName,
439+
add_user_function_api_access_rights: None,
440+
):
441+
N_OF_PROJECT_FUNCTIONS = 3
442+
N_OF_SOLVER_FUNCTIONS = 4
443+
# Register the function first
444+
registered_functions = [
445+
await functions_rpc.register_function(
446+
rabbitmq_rpc_client=rpc_client,
447+
function=mock_function,
448+
user_id=logged_user["id"],
449+
product_name=osparc_product_name,
450+
)
451+
for _ in range(N_OF_PROJECT_FUNCTIONS)
452+
]
453+
454+
solver_function = SolverFunction(
455+
title="Solver Function",
456+
description="A function that solves problems",
457+
function_class=FunctionClass.SOLVER,
458+
input_schema=JSONFunctionInputSchema(),
459+
output_schema=JSONFunctionOutputSchema(),
460+
default_inputs=None,
461+
solver_key="simcore/services/comp/foo.bar-baz_/sub-dir_1/my-service1",
462+
solver_version="0.0.0",
463+
)
464+
registered_functions.extend(
465+
[
466+
await functions_rpc.register_function(
467+
rabbitmq_rpc_client=rpc_client,
468+
function=solver_function,
469+
user_id=logged_user["id"],
470+
product_name=osparc_product_name,
471+
)
472+
for _ in range(N_OF_SOLVER_FUNCTIONS)
473+
]
474+
)
475+
476+
for function_class in [FunctionClass.PROJECT, FunctionClass.SOLVER]:
477+
# List functions with filters
478+
functions, _ = await functions_rpc.list_functions(
479+
rabbitmq_rpc_client=rpc_client,
480+
user_id=logged_user["id"],
481+
product_name=osparc_product_name,
482+
filter_by_function_class=function_class,
483+
pagination_limit=10,
484+
pagination_offset=0,
485+
)
486+
487+
# Assert the function is found
488+
assert len(functions) == (
489+
N_OF_PROJECT_FUNCTIONS
490+
if function_class == FunctionClass.PROJECT
491+
else N_OF_SOLVER_FUNCTIONS
492+
)
493+
assert all(
494+
function.uid in [f.uid for f in registered_functions]
495+
for function in functions
496+
)
497+
498+
425499
@pytest.mark.parametrize(
426500
"user_role",
427501
[UserRole.USER],

0 commit comments

Comments
 (0)