Skip to content

Commit b51b95e

Browse files
committed
fixes
1 parent a172593 commit b51b95e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
transaction_context,
2323
)
2424
from simcore_service_webserver.constants import FRONTEND_APPS_AVAILABLE
25+
from sqlalchemy.engine import Row
2526
from sqlalchemy.ext.asyncio import AsyncConnection
2627

2728
from ..constants import FRONTEND_APPS_AVAILABLE
@@ -80,6 +81,14 @@ async def _get_product_payment_fields(
8081
)
8182

8283

84+
def _to_domain(row: Row, payments: PaymentFieldsTuple) -> Product:
85+
return Product(
86+
**row._asdict(),
87+
is_payment_enabled=payments.enabled,
88+
credits_per_usd=payments.credits_per_usd,
89+
)
90+
91+
8392
class ProductRepository(BaseRepositoryV2):
8493

8594
async def list_products(
@@ -98,13 +107,8 @@ async def list_products(
98107
rows = await conn.stream(query)
99108
async for row in rows:
100109
name = row.name
101-
102110
payments = await _get_product_payment_fields(conn, product_name=name)
103-
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)
111+
app_products.append(_to_domain(row, payments))
108112

109113
assert name in FRONTEND_APPS_AVAILABLE # nosec
110114

@@ -132,11 +136,7 @@ async def get_product(
132136
payments = await _get_product_payment_fields(
133137
conn, product_name=row.name
134138
)
135-
return Product(
136-
**row._asdict(),
137-
is_payment_enabled=payments.enabled,
138-
credits_per_usd=payments.credits_per_usd,
139-
)
139+
return _to_domain(row, payments)
140140
return None
141141

142142
async def get_default_product_name(

services/web/server/tests/unit/with_dbs/04/products/test_products_repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from decimal import Decimal
99
from typing import Any
1010

11-
import aiopg.sa
1211
import pytest
1312
import sqlalchemy as sa
1413
from aiohttp import web
@@ -36,6 +35,7 @@
3635
from simcore_service_webserver.products._web_middlewares import (
3736
_get_default_product_name,
3837
)
38+
from sqlalchemy.ext.asyncio import AsyncEngine
3939

4040

4141
@pytest.fixture(scope="module")
@@ -186,10 +186,10 @@ async def product_repository(app: web.Application) -> ProductRepository:
186186
async def test_utils_products_and_webserver_default_product_in_sync(
187187
app: web.Application,
188188
product_repository: ProductRepository,
189-
aiopg_engine: aiopg.sa.engine.Engine,
189+
asyncpg_engine: AsyncEngine,
190190
):
191191
# tests definitions of default from utle_products and web-server.products are in sync
192-
async with aiopg_engine.acquire() as conn:
192+
async with asyncpg_engine.connect() as conn:
193193
default_product_name = await utils_products.get_default_product_name(conn)
194194
assert default_product_name == _get_default_product_name(app)
195195

0 commit comments

Comments
 (0)