Skip to content

Commit 891aba4

Browse files
committed
moved fixture
1 parent 60e9556 commit 891aba4

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

services/web/server/tests/unit/with_dbs/03/conftest.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66

77
from collections.abc import AsyncIterator
8+
from typing import Any
89

910
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
1113
from pytest_simcore.helpers.typing_env import EnvVarsDict
1214
from simcore_postgres_database.models.user_preferences import user_preferences_frontend
1315
from sqlalchemy.ext.asyncio import AsyncEngine
@@ -36,3 +38,41 @@ def app_environment(
3638
"WEBSERVER_TRACING": "null",
3739
},
3840
)
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

services/web/server/tests/unit/with_dbs/03/test_users_rest_profile.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
get_frontend_user_preferences_aggregation,
3434
)
3535
from sqlalchemy.exc import OperationalError as SQLAlchemyOperationalError
36-
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine
36+
from sqlalchemy.ext.asyncio import AsyncConnection
3737

3838

3939
@pytest.fixture
@@ -51,44 +51,6 @@ def app_environment(
5151
)
5252

5353

54-
@pytest.fixture
55-
async def support_group_before_app_starts(
56-
asyncpg_engine: AsyncEngine,
57-
product_name: str,
58-
) -> AsyncIterator[dict[str, Any]]:
59-
"""Creates a standard support group and assigns it to the current product"""
60-
from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan
61-
from simcore_postgres_database.models.groups import groups
62-
from simcore_postgres_database.models.products import products
63-
64-
# Create support group using direct database insertion
65-
group_values = {
66-
"name": "Support Group",
67-
"description": "Support group for product",
68-
"type": "STANDARD",
69-
}
70-
71-
# pylint: disable=contextmanager-generator-missing-cleanup
72-
async with insert_and_get_row_lifespan(
73-
asyncpg_engine,
74-
table=groups,
75-
values=group_values,
76-
pk_col=groups.c.gid,
77-
) as group_row:
78-
group_id = group_row["gid"]
79-
80-
# Update product to set support_standard_group_id
81-
async with asyncpg_engine.begin() as conn:
82-
await conn.execute(
83-
sa.update(products)
84-
.where(products.c.name == product_name)
85-
.values(support_standard_group_id=group_id)
86-
)
87-
88-
yield group_row
89-
# group will be deleted after test
90-
91-
9254
@pytest.mark.parametrize(
9355
"user_role,expected",
9456
[

0 commit comments

Comments
 (0)