|
4 | 4 |
|
5 | 5 |
|
6 | 6 | from collections.abc import AsyncIterator, Awaitable, Callable |
| 7 | +from contextlib import AsyncExitStack |
| 8 | +from typing import Any |
7 | 9 | from uuid import uuid4 |
8 | 10 |
|
9 | 11 | import pytest |
|
16 | 18 | ) |
17 | 19 | from models_library.products import ProductName |
18 | 20 | from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict |
| 21 | +from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan |
19 | 22 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
20 | 23 | from pytest_simcore.helpers.webserver_login import LoggedUser, UserInfoDict |
21 | 24 | from servicelib.rabbitmq import RabbitMQRPCClient |
@@ -189,3 +192,35 @@ async def add_user_function_api_access_rights( |
189 | 192 | funcapi_api_access_rights_table.c.group_id == group_id |
190 | 193 | ) |
191 | 194 | ) |
| 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 |
0 commit comments