|
10 | 10 | import pytest |
11 | 11 | import sqlalchemy as sa |
12 | 12 | from faker import Faker |
| 13 | +from models_library.products import ProductName |
13 | 14 | from models_library.projects import ProjectAtDB, ProjectID |
14 | 15 | from models_library.projects_nodes_io import NodeID |
| 16 | +from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan |
15 | 17 | from simcore_postgres_database.models.comp_pipeline import StateType, comp_pipeline |
16 | 18 | from simcore_postgres_database.models.comp_tasks import comp_tasks |
| 19 | +from simcore_postgres_database.models.products import products |
17 | 20 | from simcore_postgres_database.models.projects import ProjectType, projects |
| 21 | +from simcore_postgres_database.models.projects_to_products import projects_to_products |
18 | 22 | from simcore_postgres_database.models.services import services_access_rights |
19 | 23 | from simcore_postgres_database.models.users import UserRole, UserStatus, users |
20 | 24 | from simcore_postgres_database.utils_projects_nodes import ( |
@@ -63,9 +67,22 @@ def creator(**user_kwargs) -> dict[str, Any]: |
63 | 67 | print(f"<-- deleted users {created_user_ids=}") |
64 | 68 |
|
65 | 69 |
|
| 70 | +@pytest.fixture |
| 71 | +async def product_db( |
| 72 | + sqlalchemy_async_engine: AsyncEngine, product: dict[str, Any] |
| 73 | +) -> AsyncIterator[dict[str, Any]]: |
| 74 | + async with insert_and_get_row_lifespan( # pylint:disable=contextmanager-generator-missing-cleanup |
| 75 | + sqlalchemy_async_engine, |
| 76 | + table=products, |
| 77 | + values=product, |
| 78 | + pk_col=products.c.name, |
| 79 | + ) as created_product: |
| 80 | + yield created_product |
| 81 | + |
| 82 | + |
66 | 83 | @pytest.fixture |
67 | 84 | async def project( |
68 | | - sqlalchemy_async_engine: AsyncEngine, faker: Faker |
| 85 | + sqlalchemy_async_engine: AsyncEngine, faker: Faker, product_name: ProductName |
69 | 86 | ) -> AsyncIterator[Callable[..., Awaitable[ProjectAtDB]]]: |
70 | 87 | created_project_ids: list[str] = [] |
71 | 88 |
|
@@ -113,6 +130,12 @@ async def creator( |
113 | 130 | for node_id in inserted_project.workbench |
114 | 131 | ], |
115 | 132 | ) |
| 133 | + await con.execute( |
| 134 | + projects_to_products.insert().values( |
| 135 | + project_uuid=f"{inserted_project.uuid}", |
| 136 | + product_name=product_name, |
| 137 | + ) |
| 138 | + ) |
116 | 139 | print(f"--> created {inserted_project=}") |
117 | 140 | created_project_ids.append(f"{inserted_project.uuid}") |
118 | 141 | return inserted_project |
|
0 commit comments