Skip to content

Commit d5bdd7d

Browse files
committed
feat: add fixture for user function API access rights and corresponding test
1 parent d4ad564 commit d5bdd7d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
from collections.abc import AsyncIterator, Awaitable, Callable
7+
from contextlib import AsyncExitStack
8+
from typing import Any
79
from uuid import uuid4
810

911
import pytest
@@ -16,6 +18,7 @@
1618
)
1719
from models_library.products import ProductName
1820
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
21+
from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan
1922
from pytest_simcore.helpers.typing_env import EnvVarsDict
2023
from pytest_simcore.helpers.webserver_login import LoggedUser, UserInfoDict
2124
from servicelib.rabbitmq import RabbitMQRPCClient
@@ -189,3 +192,35 @@ async def add_user_function_api_access_rights(
189192
funcapi_api_access_rights_table.c.group_id == group_id
190193
)
191194
)
195+
196+
197+
@pytest.fixture
198+
async def logged_user_function_api_access_rights(
199+
asyncpg_engine: AsyncEngine,
200+
logged_user: UserInfoDict,
201+
*,
202+
expected_write_functions: bool,
203+
) -> AsyncIterator[dict[str, Any]]:
204+
cm = insert_and_get_row_lifespan(
205+
asyncpg_engine,
206+
table=funcapi_api_access_rights_table,
207+
values={
208+
"group_id": logged_user["primary_gid"],
209+
"product_name": FRONTEND_APP_DEFAULT,
210+
"read_functions": True,
211+
"write_functions": expected_write_functions,
212+
"execute_functions": True,
213+
"read_function_jobs": True,
214+
"write_function_jobs": True,
215+
"execute_function_jobs": True,
216+
"read_function_job_collections": True,
217+
"write_function_job_collections": True,
218+
"execute_function_job_collections": True,
219+
},
220+
pk_col=funcapi_api_access_rights_table.c.group_id,
221+
pk_value=logged_user["primary_gid"],
222+
)
223+
224+
async with AsyncExitStack() as stack:
225+
row = await stack.enter_async_context(cm)
226+
yield row

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
JSONFunctionOutputSchema,
1818
RegisteredProjectFunctionGet,
1919
)
20+
from models_library.api_schemas_webserver.users import MyFunctionPermissionsGet
2021
from pytest_simcore.helpers.assert_checks import assert_status
2122
from pytest_simcore.helpers.webserver_login import UserInfoDict
2223
from servicelib.aiohttp import status
@@ -111,3 +112,24 @@ async def test_register_get_delete_function(
111112
)
112113
response = await client.get(url)
113114
data, error = await assert_status(response, expected_get2)
115+
116+
117+
@pytest.mark.parametrize("expected_write_functions", [True, False])
118+
async def test_list_user_functions_permissions(
119+
client: TestClient,
120+
logged_user: UserInfoDict,
121+
expected_write_functions: bool,
122+
logged_user_function_api_access_rights: dict[str, Any],
123+
):
124+
assert (
125+
logged_user_function_api_access_rights["write_functions"]
126+
== expected_write_functions
127+
)
128+
129+
url = client.app.router["list_user_functions_permissions"].url_for()
130+
response = await client.get(url)
131+
data, error = await assert_status(response, expected_status_code=status.HTTP_200_OK)
132+
133+
assert not error
134+
function_permissions = MyFunctionPermissionsGet.model_validate(data)
135+
assert function_permissions.write_functions == expected_write_functions

0 commit comments

Comments
 (0)