Skip to content

Commit de88627

Browse files
committed
Add more tests
1 parent db50854 commit de88627

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

services/api-server/src/simcore_service_api_server/api/routes/functions_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from models_library.functions_errors import (
2626
FunctionExecuteAccessDeniedError,
2727
FunctionInputsValidationError,
28-
FunctionsExecuteAbilityDeniedError,
28+
FunctionsExecuteApiAccessDeniedError,
2929
UnsupportedFunctionClassError,
3030
)
3131
from models_library.products import ProductName
@@ -380,7 +380,7 @@ async def run_function( # noqa: PLR0913
380380
user_id=user_id, product_name=product_name
381381
)
382382
if not user_abilities.execute_functions:
383-
raise FunctionsExecuteAbilityDeniedError(
383+
raise FunctionsExecuteApiAccessDeniedError(
384384
user_id=user_id,
385385
function_id=function_id,
386386
)

services/api-server/tests/unit/api_functions/test_api_routers_functions.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,10 @@ async def test_list_function_job_collections_with_function_filter(
592592

593593

594594
@pytest.mark.parametrize("user_has_execute_ability", [False, True])
595-
async def test_run_function_not_allowed(
595+
@pytest.mark.parametrize(
596+
"funcapi_endpoint,endpoint_inputs", [("run", {}), ("map", [{}, {}])]
597+
)
598+
async def test_run_map_function_not_allowed(
596599
client: AsyncClient,
597600
mock_handler_in_functions_rpc_interface: Callable[[str, Any], None],
598601
mock_registered_function: RegisteredProjectFunction,
@@ -601,6 +604,8 @@ async def test_run_function_not_allowed(
601604
mocked_webserver_rest_api_base: respx.MockRouter,
602605
mocked_webserver_rpc_api: dict[str, MockType],
603606
user_has_execute_ability: bool,
607+
funcapi_endpoint: str,
608+
endpoint_inputs: dict | list[dict],
604609
) -> None:
605610
"""Test that running a function is not allowed."""
606611

@@ -631,8 +636,8 @@ async def async_magic():
631636
MagicMock.__await__ = lambda _: async_magic().__await__()
632637

633638
response = await client.post(
634-
f"{API_VTAG}/functions/{mock_registered_function.uid}:run",
635-
json={},
639+
f"{API_VTAG}/functions/{mock_registered_function.uid}:{funcapi_endpoint}",
640+
json=endpoint_inputs,
636641
auth=auth,
637642
)
638643
if user_has_execute_ability:

services/web/server/tests/unit/with_dbs/04/functions_rpc/test_functions_controller_rest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def mock_function() -> dict[str, Any]:
4949

5050

5151
@pytest.mark.parametrize(
52-
"user_role,add_user_functions_abilities,expected_register,expected_get,expected_delete,expected_get2",
52+
"user_role,add_user_function_api_access_rights,expected_register,expected_get,expected_delete,expected_get2",
5353
[
5454
(
5555
UserRole.USER,
@@ -68,7 +68,7 @@ def mock_function() -> dict[str, Any]:
6868
status.HTTP_403_FORBIDDEN,
6969
),
7070
],
71-
indirect=["add_user_functions_abilities"],
71+
indirect=["add_user_function_api_access_rights"],
7272
)
7373
async def test_register_get_delete_function(
7474
client: TestClient,
@@ -78,7 +78,7 @@ async def test_register_get_delete_function(
7878
expected_get: HTTPStatus,
7979
expected_delete: HTTPStatus,
8080
expected_get2: HTTPStatus,
81-
add_user_functions_abilities: AsyncIterator[None],
81+
add_user_function_api_access_rights: AsyncIterator[None],
8282
request: pytest.FixtureRequest,
8383
) -> None:
8484
url = client.app.router["register_function"].url_for()

0 commit comments

Comments
 (0)