|
6 | 6 | from collections.abc import AsyncIterator, Awaitable, Callable |
7 | 7 | from contextlib import AsyncExitStack |
8 | 8 | from typing import Any |
9 | | -from uuid import uuid4 |
| 9 | +from uuid import UUID, uuid4 |
10 | 10 |
|
11 | 11 | import pytest |
12 | 12 | import sqlalchemy |
|
31 | 31 | from simcore_postgres_database.models.funcapi_api_access_rights_table import ( |
32 | 32 | funcapi_api_access_rights_table, |
33 | 33 | ) |
| 34 | +from simcore_postgres_database.models.funcapi_function_jobs_table import ( |
| 35 | + function_jobs_table, |
| 36 | +) |
| 37 | +from simcore_postgres_database.models.funcapi_functions_access_rights_table import ( |
| 38 | + functions_access_rights_table, |
| 39 | +) |
| 40 | +from simcore_postgres_database.models.funcapi_functions_table import functions_table |
34 | 41 | from simcore_service_webserver.application_settings import ApplicationSettings |
35 | 42 | from simcore_service_webserver.statics._constants import FRONTEND_APP_DEFAULT |
36 | 43 | from sqlalchemy.ext.asyncio import AsyncEngine |
@@ -253,3 +260,71 @@ async def logged_user_function_api_access_rights( |
253 | 260 | async with AsyncExitStack() as stack: |
254 | 261 | row = await stack.enter_async_context(cm) |
255 | 262 | yield row |
| 263 | + |
| 264 | + |
| 265 | +@pytest.fixture |
| 266 | +async def fake_function_with_associated_job( |
| 267 | + asyncpg_engine: AsyncEngine, |
| 268 | + logged_user: UserInfoDict, |
| 269 | +) -> AsyncIterator[UUID]: |
| 270 | + async with AsyncExitStack() as stack: |
| 271 | + function_row = await stack.enter_async_context( |
| 272 | + insert_and_get_row_lifespan( |
| 273 | + asyncpg_engine, |
| 274 | + table=functions_table, |
| 275 | + values={ |
| 276 | + "title": "Test Function", |
| 277 | + "function_class": FunctionClass.PROJECT.value, |
| 278 | + "description": "A test function", |
| 279 | + "input_schema": { |
| 280 | + "schema_class": "application/schema+json", |
| 281 | + "schema_content": { |
| 282 | + "type": "object", |
| 283 | + "properties": {"input1": {"type": "string"}}, |
| 284 | + }, |
| 285 | + }, |
| 286 | + "output_schema": { |
| 287 | + "schema_class": "application/schema+json", |
| 288 | + "schema_content": { |
| 289 | + "type": "object", |
| 290 | + "properties": {"output1": {"type": "string"}}, |
| 291 | + }, |
| 292 | + }, |
| 293 | + "class_specific_data": {"project_id": f"{uuid4()}"}, |
| 294 | + }, |
| 295 | + pk_col=functions_table.c.uuid, |
| 296 | + ) |
| 297 | + ) |
| 298 | + |
| 299 | + await stack.enter_async_context( |
| 300 | + insert_and_get_row_lifespan( |
| 301 | + asyncpg_engine, |
| 302 | + table=functions_access_rights_table, |
| 303 | + values={ |
| 304 | + "function_uuid": function_row["uuid"], |
| 305 | + "group_id": logged_user["primary_gid"], |
| 306 | + "product_name": "osparc", # Default product name |
| 307 | + "read": True, |
| 308 | + "write": True, |
| 309 | + "execute": True, |
| 310 | + }, |
| 311 | + pk_cols=[ |
| 312 | + functions_access_rights_table.c.function_uuid, |
| 313 | + functions_access_rights_table.c.group_id, |
| 314 | + functions_access_rights_table.c.product_name, |
| 315 | + ], |
| 316 | + ) |
| 317 | + ) |
| 318 | + |
| 319 | + await stack.enter_async_context( |
| 320 | + insert_and_get_row_lifespan( |
| 321 | + asyncpg_engine, |
| 322 | + table=function_jobs_table, |
| 323 | + values={ |
| 324 | + "function_uuid": function_row["uuid"], |
| 325 | + "status": "pending", |
| 326 | + }, |
| 327 | + pk_col=function_jobs_table.c.uuid, |
| 328 | + ) |
| 329 | + ) |
| 330 | + yield function_row["uuid"] |
0 commit comments