33# pylint: disable=redefined-outer-name
44# pylint: disable=unused-argument
55
6-
76import asyncio
87from collections .abc import Callable
98
109import pytest
1110import sqlalchemy as sa
12- from aiopg .sa .engine import Engine
1311from simcore_postgres_database .models .groups import GroupType , groups
1412from simcore_postgres_database .models .products import products
1513from 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
3638async 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)
107108async 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