Skip to content

Commit 58cc491

Browse files
committed
renames
1 parent dde9914 commit 58cc491

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
_GroupID = int
1111

1212

13+
class EmptyProductsError(ValueError): ...
14+
15+
1316
async def get_default_product_name(conn: AsyncConnection) -> str:
1417
"""The first row in the table is considered as the default product
1518
@@ -19,14 +22,14 @@ async def get_default_product_name(conn: AsyncConnection) -> str:
1922
sa.select(products.c.name).order_by(products.c.priority)
2023
)
2124
if not product_name:
22-
msg = "No product defined in database"
23-
raise ValueError(msg)
25+
msg = "No product was defined in database. Upon construction, at least one product is added but there are none."
26+
raise EmptyProductsError(msg)
2427

2528
assert isinstance(product_name, str) # nosec
2629
return product_name
2730

2831

29-
async def get_product_group_id(
32+
async def get_product_group_id_or_none(
3033
connection: AsyncConnection, product_name: str
3134
) -> _GroupID | None:
3235
group_id = await connection.scalar(
@@ -35,7 +38,9 @@ async def get_product_group_id(
3538
return None if group_id is None else _GroupID(group_id)
3639

3740

38-
async def get_or_create_product_group(conn: AsyncConnection, product_name: str) -> int:
41+
async def get_or_create_product_group(
42+
conn: AsyncConnection, product_name: str
43+
) -> _GroupID:
3944
#
4045
# NOTE: Separated so it can be used in asyncpg and aiopg environs while both
4146
# coexist

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from simcore_postgres_database.models.groups import GroupType, groups
1111
from simcore_postgres_database.models.products import products
1212
from simcore_postgres_database.utils_products import (
13+
EmptyProductsError,
1314
get_default_product_name,
1415
get_or_create_product_group,
15-
get_product_group_id,
16+
get_product_group_id_or_none,
1617
)
1718
from sqlalchemy.ext.asyncio import AsyncEngine
1819

@@ -29,7 +30,7 @@ async def test_default_product(
2930
@pytest.mark.parametrize("pg_sa_engine", ["sqlModels"], indirect=True)
3031
async def test_default_product_undefined(asyncpg_engine: AsyncEngine):
3132
async with asyncpg_engine.connect() as conn:
32-
with pytest.raises(ValueError, match="No product"):
33+
with pytest.raises(EmptyProductsError):
3334
await get_default_product_name(conn)
3435

3536

@@ -79,22 +80,22 @@ async def test_get_or_create_group_product(
7980
)
8081
assert result.one()
8182

82-
assert product_group_id == await get_product_group_id(
83+
assert product_group_id == await get_product_group_id_or_none(
8384
conn, product_name=product_row.name
8485
)
8586

8687
# group-id is UPDATED -> product.group_id is updated to the new value
8788
await conn.execute(
8889
groups.update().where(groups.c.gid == product_group_id).values(gid=1000)
8990
)
90-
product_group_id = await get_product_group_id(
91+
product_group_id = await get_product_group_id_or_none(
9192
conn, product_name=product_row.name
9293
)
9394
assert product_group_id == 1000
9495

9596
# if group is DELETED -> product.group_id=null
9697
await conn.execute(groups.delete().where(groups.c.gid == product_group_id))
97-
product_group_id = await get_product_group_id(
98+
product_group_id = await get_product_group_id_or_none(
9899
conn, product_name=product_row.name
99100
)
100101
assert product_group_id is None

0 commit comments

Comments
 (0)