Skip to content

Commit a172593

Browse files
committed
product and get|create
1 parent c449c92 commit a172593

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ async def get_product_group_id(
3535
return None if group_id is None else _GroupID(group_id)
3636

3737

38-
async def execute_get_or_create_product_group(
39-
conn: AsyncConnection, product_name: str
40-
) -> int:
38+
async def get_or_create_product_group(conn: AsyncConnection, product_name: str) -> int:
4139
#
4240
# NOTE: Separated so it can be used in asyncpg and aiopg environs while both
4341
# coexist

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
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-
execute_get_or_create_product_group,
1413
get_default_product_name,
14+
get_or_create_product_group,
1515
get_product_group_id,
1616
)
1717
from sqlalchemy.ext.asyncio import AsyncEngine
@@ -45,7 +45,7 @@ async def test_get_or_create_group_product(
4545
)
4646
):
4747
# get or create
48-
product_group_id = await execute_get_or_create_product_group(
48+
product_group_id = await get_or_create_product_group(
4949
conn, product_name=product_row.name
5050
)
5151

@@ -67,7 +67,7 @@ async def test_get_or_create_group_product(
6767
# idempotent
6868
for _ in range(3):
6969
assert (
70-
await execute_get_or_create_product_group(
70+
await get_or_create_product_group(
7171
conn, product_name=product_row.name
7272
)
7373
== product_group_id

services/web/server/src/simcore_service_webserver/groups/_groups_repository.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from models_library.users import UserID
2121
from simcore_postgres_database.errors import UniqueViolation
2222
from simcore_postgres_database.models.users import users
23-
from simcore_postgres_database.utils_products import execute_get_or_create_product_group
23+
from simcore_postgres_database.utils_products import get_or_create_product_group
2424
from simcore_postgres_database.utils_repos import (
2525
pass_or_acquire_connection,
2626
transaction_context,
@@ -173,7 +173,6 @@ async def get_all_user_groups_with_read_access(
173173
*,
174174
user_id: UserID,
175175
) -> GroupsByTypeTuple:
176-
177176
"""
178177
Returns the user primary group, standard groups and the all group
179178
"""
@@ -758,7 +757,7 @@ async def auto_add_user_to_product_group(
758757
product_name: str,
759758
) -> GroupID:
760759
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
761-
product_group_id: GroupID = await execute_get_or_create_product_group(
760+
product_group_id: GroupID = await get_or_create_product_group(
762761
conn, product_name
763762
)
764763

services/web/server/src/simcore_service_webserver/products/_repository.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from simcore_postgres_database.models.jinja2_templates import jinja2_templates
1010
from simcore_postgres_database.models.products import products
1111
from simcore_postgres_database.utils_products import (
12-
execute_get_or_create_product_group,
1312
get_default_product_name,
13+
get_or_create_product_group,
1414
)
1515
from simcore_postgres_database.utils_products_prices import (
1616
ProductPriceInfo,
@@ -101,13 +101,10 @@ async def list_products(
101101

102102
payments = await _get_product_payment_fields(conn, product_name=name)
103103

104-
app_products.append(
105-
Product(
106-
**dict(row.items()),
107-
is_payment_enabled=payments.enabled,
108-
credits_per_usd=payments.credits_per_usd,
109-
)
110-
)
104+
product = Product.model_validate(row, from_attributes=True)
105+
product.is_payment_enabled = payments.enabled
106+
product.credits_per_usd = payments.credits_per_usd
107+
app_products.append(product)
111108

112109
assert name in FRONTEND_APPS_AVAILABLE # nosec
113110

@@ -219,7 +216,7 @@ async def auto_create_products_groups(
219216
for product_name in product_names:
220217
# NOTE: transaction is per product. fail-fast!
221218
async with transaction_context(self.engine, connection) as conn:
222-
product_group_id: GroupID = await execute_get_or_create_product_group(
219+
product_group_id: GroupID = await get_or_create_product_group(
223220
conn, product_name
224221
)
225222
product_groups_map[product_name] = product_group_id

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
from simcore_postgres_database.models.products import products
6565
from simcore_postgres_database.models.products_prices import products_prices
6666
from simcore_postgres_database.utils_products import (
67-
execute_get_or_create_product_group,
6867
get_default_product_name,
68+
get_or_create_product_group,
6969
)
7070
from simcore_service_webserver.application import create_application
7171
from simcore_service_webserver.application_settings_utils import AppConfigDict
@@ -745,7 +745,7 @@ async def all_products_names(
745745
)
746746
)
747747
)
748-
await execute_get_or_create_product_group(conn, product_name=name)
748+
await get_or_create_product_group(conn, product_name=name)
749749
priority += 1
750750

751751
async with asyncpg_engine.connect() as conn:

0 commit comments

Comments
 (0)