Skip to content

Commit 4807c22

Browse files
committed
cleanup
1 parent 7ee99b1 commit 4807c22

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_products.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
_GroupID = int
1414

1515

16-
async def get_default_product_name(conn: AsyncConnection | SAConnection) -> str:
16+
async def get_default_product_name(conn: AsyncConnection) -> str:
1717
"""The first row in the table is considered as the default product
1818
1919
:: raises ValueError if undefined
@@ -30,7 +30,7 @@ async def get_default_product_name(conn: AsyncConnection | SAConnection) -> str:
3030

3131

3232
async def get_product_group_id(
33-
connection: SAConnection, product_name: str
33+
connection: AsyncConnection, product_name: str
3434
) -> _GroupID | None:
3535
group_id = await connection.scalar(
3636
sa.select(products.c.group_id).where(products.c.name == product_name)
@@ -39,7 +39,7 @@ async def get_product_group_id(
3939

4040

4141
async def execute_get_or_create_product_group(
42-
conn: AsyncConnection, product_name: str
42+
conn: AsyncConnection | SAConnection, product_name: str
4343
) -> int:
4444
#
4545
# NOTE: Separated so it can be used in asyncpg and aiopg environs while both

packages/postgres-database/tests/products/test_utils_products.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,51 @@
33
# pylint: disable=redefined-outer-name
44
# pylint: disable=unused-argument
55

6-
76
import asyncio
87
from collections.abc import Callable
98

109
import pytest
1110
import sqlalchemy as sa
12-
from aiopg.sa.engine import Engine
1311
from simcore_postgres_database.models.groups import GroupType, groups
1412
from simcore_postgres_database.models.products import products
1513
from simcore_postgres_database.utils_products import (
14+
execute_get_or_create_product_group,
1615
get_default_product_name,
1716
get_or_create_product_group,
1817
get_product_group_id,
1918
)
19+
from sqlalchemy.ext.asyncio import AsyncEngine
2020

2121

22-
async def test_default_product(aiopg_engine: Engine, make_products_table: Callable):
23-
async with aiopg_engine.acquire() as conn:
22+
async def test_default_product(
23+
asyncpg_engine: AsyncEngine, make_products_table: Callable
24+
):
25+
async with asyncpg_engine.connect() as conn:
2426
await make_products_table(conn)
2527
default_product = await get_default_product_name(conn)
2628
assert default_product == "s4l"
2729

2830

2931
@pytest.mark.parametrize("pg_sa_engine", ["sqlModels"], indirect=True)
30-
async def test_default_product_undefined(aiopg_engine: Engine):
31-
async with aiopg_engine.acquire() as conn:
32+
async def test_default_product_undefined(asyncpg_engine: AsyncEngine):
33+
async with asyncpg_engine.connect() as conn:
3234
with pytest.raises(ValueError):
3335
await get_default_product_name(conn)
3436

3537

3638
async def test_get_or_create_group_product(
37-
aiopg_engine: Engine, make_products_table: Callable
39+
asyncpg_engine: AsyncEngine, make_products_table: Callable
3840
):
39-
async with aiopg_engine.acquire() as conn:
41+
async with asyncpg_engine.connect() as conn:
4042
await make_products_table(conn)
4143

42-
async for product_row in await conn.execute(
44+
async for product_row in await conn.stream(
4345
sa.select(products.c.name, products.c.group_id).order_by(
4446
products.c.priority
4547
)
4648
):
4749
# get or create
48-
product_group_id = await get_or_create_product_group(
50+
product_group_id = await execute_get_or_create_product_group(
4951
conn, product_name=product_row.name
5052
)
5153

@@ -57,8 +59,7 @@ async def test_get_or_create_group_product(
5759
result = await conn.execute(
5860
groups.select().where(groups.c.gid == product_group_id)
5961
)
60-
assert result.rowcount == 1
61-
product_group = await result.first()
62+
product_group = result.one()
6263

6364
# check product's group
6465
assert product_group.type == GroupType.STANDARD
@@ -68,7 +69,7 @@ async def test_get_or_create_group_product(
6869
# idempotent
6970
for _ in range(3):
7071
assert (
71-
await get_or_create_product_group(
72+
await execute_get_or_create_product_group(
7273
conn, product_name=product_row.name
7374
)
7475
== product_group_id
@@ -78,7 +79,7 @@ async def test_get_or_create_group_product(
7879
result = await conn.execute(
7980
groups.select().where(groups.c.name == product_row.name)
8081
)
81-
assert result.rowcount == 1
82+
assert result.one()
8283

8384
assert product_group_id == await get_product_group_id(
8485
conn, product_name=product_row.name
@@ -105,14 +106,14 @@ async def test_get_or_create_group_product(
105106
reason="Not relevant. Will review in https://github.com/ITISFoundation/osparc-simcore/issues/3754"
106107
)
107108
async def test_get_or_create_group_product_concurrent(
108-
aiopg_engine: Engine, make_products_table: Callable
109+
asyncpg_engine: AsyncEngine, make_products_table: Callable
109110
):
110-
async with aiopg_engine.acquire() as conn:
111+
async with asyncpg_engine.connect() as conn:
111112
await make_products_table(conn)
112113

113114
async def _auto_create_products_groups():
114-
async with aiopg_engine.acquire() as conn:
115-
async for product_row in await conn.execute(
115+
async with asyncpg_engine.connect() as conn:
116+
async for product_row in await conn.stream(
116117
sa.select(products.c.name, products.c.group_id).order_by(
117118
products.c.priority
118119
)

0 commit comments

Comments
 (0)