|
5 | 5 |
|
6 | 6 |
|
7 | 7 | from collections.abc import AsyncIterator |
| 8 | +from typing import Any |
8 | 9 |
|
9 | 10 | import pytest |
10 | | -from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict |
| 11 | +import sqlalchemy as sa |
| 12 | +from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict |
11 | 13 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
12 | 14 | from simcore_postgres_database.models.user_preferences import user_preferences_frontend |
13 | 15 | from sqlalchemy.ext.asyncio import AsyncEngine |
@@ -36,3 +38,41 @@ def app_environment( |
36 | 38 | "WEBSERVER_TRACING": "null", |
37 | 39 | }, |
38 | 40 | ) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.fixture |
| 44 | +async def support_group_before_app_starts( |
| 45 | + asyncpg_engine: AsyncEngine, |
| 46 | + product_name: str, |
| 47 | +) -> AsyncIterator[dict[str, Any]]: |
| 48 | + """Creates a standard support group and assigns it to the current product""" |
| 49 | + from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan |
| 50 | + from simcore_postgres_database.models.groups import groups |
| 51 | + from simcore_postgres_database.models.products import products |
| 52 | + |
| 53 | + # Create support group using direct database insertion |
| 54 | + group_values = { |
| 55 | + "name": "Support Group", |
| 56 | + "description": "Support group for product", |
| 57 | + "type": "STANDARD", |
| 58 | + } |
| 59 | + |
| 60 | + # pylint: disable=contextmanager-generator-missing-cleanup |
| 61 | + async with insert_and_get_row_lifespan( |
| 62 | + asyncpg_engine, |
| 63 | + table=groups, |
| 64 | + values=group_values, |
| 65 | + pk_col=groups.c.gid, |
| 66 | + ) as group_row: |
| 67 | + group_id = group_row["gid"] |
| 68 | + |
| 69 | + # Update product to set support_standard_group_id |
| 70 | + async with asyncpg_engine.begin() as conn: |
| 71 | + await conn.execute( |
| 72 | + sa.update(products) |
| 73 | + .where(products.c.name == product_name) |
| 74 | + .values(support_standard_group_id=group_id) |
| 75 | + ) |
| 76 | + |
| 77 | + yield group_row |
| 78 | + # group will be deleted after test |
0 commit comments