11# pylint: disable=inconsistent-return-statements
22# pylint: disable=redefined-outer-name
33
4- from collections .abc import Awaitable , Callable
4+ from collections .abc import AsyncIterator , Awaitable , Callable
55from typing import Any
66
77import pytest
8- from aiopg .sa .connection import SAConnection
8+ from aiopg .sa .connection import AsyncConnection
99from aiopg .sa .result import RowProxy
1010from faker import Faker
1111from pytest_simcore .helpers .faker_factories import random_user
1515 FrontendUserPreferencesRepo ,
1616 UserServicesUserPreferencesRepo ,
1717)
18+ from sqlalchemy .ext .asyncio import AsyncConnection , AsyncEngine
1819
1920
2021@pytest .fixture
@@ -38,8 +39,16 @@ def preference_repo(request: pytest.FixtureRequest) -> type[BasePreferencesRepo]
3839 return request .param
3940
4041
42+ @pytest .fixture
43+ async def connection (
44+ asyncpg_engine : AsyncEngine ,
45+ ) -> AsyncIterator [AsyncConnection ]:
46+ async with asyncpg_engine .begin () as connection :
47+ yield connection
48+
49+
4150async def _assert_save_get_preference (
42- connection : SAConnection ,
51+ connection : AsyncConnection ,
4352 preference_repo : type [BasePreferencesRepo ],
4453 * ,
4554 user_id : int ,
@@ -65,7 +74,7 @@ async def _assert_save_get_preference(
6574
6675
6776async def _assert_preference_not_saved (
68- connection : SAConnection ,
77+ connection : AsyncConnection ,
6978 preference_repo : type [BasePreferencesRepo ],
7079 * ,
7180 user_id : int ,
@@ -92,7 +101,7 @@ def _get_random_payload(
92101 pytest .fail (f"Did not define a casa for { preference_repo = } . Please add one." )
93102
94103
95- async def _get_user_id (connection : SAConnection , faker : Faker ) -> int :
104+ async def _get_user_id (connection : AsyncConnection , faker : Faker ) -> int :
96105 data = random_user (role = faker .random_element (elements = UserRole ))
97106 user_id = await connection .scalar (
98107 users .insert ().values (** data ).returning (users .c .id )
@@ -102,7 +111,7 @@ async def _get_user_id(connection: SAConnection, faker: Faker) -> int:
102111
103112
104113async def test_user_preference_repo_workflow (
105- connection : SAConnection ,
114+ connection : AsyncConnection ,
106115 preference_repo : type [BasePreferencesRepo ],
107116 preference_one : str ,
108117 product_name : str ,
@@ -144,7 +153,7 @@ async def test_user_preference_repo_workflow(
144153
145154
146155async def test__same_preference_name_product_name__different_users (
147- connection : SAConnection ,
156+ connection : AsyncConnection ,
148157 preference_repo : type [BasePreferencesRepo ],
149158 preference_one : str ,
150159 product_name : str ,
@@ -193,7 +202,7 @@ async def test__same_preference_name_product_name__different_users(
193202
194203
195204async def test__same_user_preference_name__different_product_name (
196- connection : SAConnection ,
205+ connection : AsyncConnection ,
197206 create_fake_product : Callable [..., Awaitable [RowProxy ]],
198207 preference_repo : type [BasePreferencesRepo ],
199208 preference_one : str ,
@@ -244,7 +253,7 @@ async def test__same_user_preference_name__different_product_name(
244253
245254
246255async def test__same_product_name_user__different_preference_name (
247- connection : SAConnection ,
256+ connection : AsyncConnection ,
248257 preference_repo : type [BasePreferencesRepo ],
249258 preference_one : str ,
250259 preference_two : str ,
0 commit comments