Skip to content

Commit a2e009f

Browse files
authored
♻️Director-v2: removed aiopg dependency also from tests (#7638)
1 parent fc62ac0 commit a2e009f

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

packages/postgres-database/tests/test_comp_tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import asyncio
77
import json
8+
from collections.abc import AsyncIterator
89

910
import pytest
1011
from aiopg.sa.engine import Engine, SAConnection
@@ -25,7 +26,9 @@ async def db_connection(aiopg_engine: Engine) -> SAConnection:
2526

2627

2728
@pytest.fixture()
28-
async def db_notification_queue(db_connection: SAConnection) -> asyncio.Queue:
29+
async def db_notification_queue(
30+
db_connection: SAConnection,
31+
) -> AsyncIterator[asyncio.Queue]:
2932
listen_query = f"LISTEN {DB_CHANNEL_NAME};"
3033
await db_connection.execute(listen_query)
3134
notifications_queue: asyncio.Queue = db_connection.connection.notifies

packages/pytest-simcore/src/pytest_simcore/db_entries_mocks.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Any
88
from uuid import uuid4
99

10-
import aiopg.sa
1110
import pytest
1211
import sqlalchemy as sa
1312
from faker import Faker
@@ -20,6 +19,7 @@
2019
ProjectNodeCreate,
2120
ProjectNodesRepo,
2221
)
22+
from sqlalchemy.ext.asyncio import AsyncEngine
2323

2424

2525
@pytest.fixture()
@@ -63,7 +63,7 @@ def creator(**user_kwargs) -> dict[str, Any]:
6363

6464
@pytest.fixture
6565
async def project(
66-
aiopg_engine: aiopg.sa.engine.Engine, faker: Faker
66+
sqlalchemy_async_engine: AsyncEngine, faker: Faker
6767
) -> AsyncIterator[Callable[..., Awaitable[ProjectAtDB]]]:
6868
created_project_ids: list[str] = []
6969

@@ -86,17 +86,22 @@ async def creator(
8686
"workbench": {},
8787
}
8888
project_config.update(**project_overrides)
89-
async with aiopg_engine.acquire() as con, con.begin():
89+
async with sqlalchemy_async_engine.connect() as con, con.begin():
9090
result = await con.execute(
9191
projects.insert()
9292
.values(**project_config)
9393
.returning(sa.literal_column("*"))
9494
)
9595

96-
inserted_project = ProjectAtDB.model_validate(await result.first())
96+
inserted_project = ProjectAtDB.model_validate(result.one())
9797
project_nodes_repo = ProjectNodesRepo(project_uuid=project_uuid)
9898
# NOTE: currently no resources is passed until it becomes necessary
99-
default_node_config = {"required_resources": {}, "key": faker.pystr(), "version": faker.pystr(), "label": faker.pystr()}
99+
default_node_config = {
100+
"required_resources": {},
101+
"key": faker.pystr(),
102+
"version": faker.pystr(),
103+
"label": faker.pystr(),
104+
}
100105
if project_nodes_overrides:
101106
default_node_config.update(project_nodes_overrides)
102107
await project_nodes_repo.add(
@@ -113,17 +118,15 @@ async def creator(
113118
yield creator
114119

115120
# cleanup
116-
async with aiopg_engine.acquire() as con:
121+
async with sqlalchemy_async_engine.begin() as con:
117122
await con.execute(
118123
projects.delete().where(projects.c.uuid.in_(created_project_ids))
119124
)
120125
print(f"<-- delete projects {created_project_ids=}")
121126

122127

123128
@pytest.fixture
124-
def pipeline(
125-
postgres_db: sa.engine.Engine,
126-
) -> Iterator[Callable[..., dict[str, Any]]]:
129+
def pipeline(postgres_db: sa.engine.Engine) -> Iterator[Callable[..., dict[str, Any]]]:
127130
created_pipeline_ids: list[str] = []
128131

129132
def creator(**pipeline_kwargs) -> dict[str, Any]:

packages/pytest-simcore/src/pytest_simcore/postgres_service.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
# pylint: disable=unused-variable
44

55
import json
6+
import warnings
67
from collections.abc import AsyncIterator, Iterator
78
from typing import Final
89

910
import docker
1011
import pytest
1112
import sqlalchemy as sa
1213
import tenacity
13-
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
14-
from pytest_simcore.helpers.typing_env import EnvVarsDict
1514
from sqlalchemy.ext.asyncio import AsyncEngine
1615
from tenacity.stop import stop_after_delay
1716
from tenacity.wait import wait_fixed
1817

1918
from .helpers.docker import get_service_published_port
2019
from .helpers.host import get_localhost_ip
20+
from .helpers.monkeypatch_envs import setenvs_from_dict
2121
from .helpers.postgres_tools import PostgresTestConfig, migrated_pg_tables_context
22+
from .helpers.typing_env import EnvVarsDict
2223

2324
_TEMPLATE_DB_TO_RESTORE = "template_simcore_db"
2425

@@ -212,6 +213,12 @@ async def aiopg_engine(
212213

213214
engine = await create_engine(str(postgres_db.url))
214215

216+
warnings.warn(
217+
"The 'aiopg_engine' fixture is deprecated and will be removed in a future release. "
218+
"Please use 'asyncpg_engine' fixture instead.",
219+
DeprecationWarning,
220+
stacklevel=2,
221+
)
215222
yield engine
216223

217224
if engine:

services/director-v2/requirements/_test.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
aio_pika
1313
aioboto3
14-
aiopg[sa]
1514
alembic # migration due to pytest_simcore.postgres_service2
1615
asgi_lifespan
1716
async-asgi-testclient # replacement for fastapi.testclient.TestClient [see b) below]

services/director-v2/requirements/_test.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ aiohttp==3.11.13
2121
# aiobotocore
2222
aioitertools==0.12.0
2323
# via aiobotocore
24-
aiopg==1.4.0
25-
# via -r requirements/_test.in
2624
aiormq==6.8.1
2725
# via
2826
# -c requirements/_base.txt
@@ -43,8 +41,6 @@ asgi-lifespan==2.1.0
4341
# via -r requirements/_test.in
4442
async-asgi-testclient==1.4.11
4543
# via -r requirements/_test.in
46-
async-timeout==4.0.3
47-
# via aiopg
4844
attrs==25.1.0
4945
# via
5046
# -c requirements/_base.txt
@@ -227,11 +223,6 @@ psutil==6.1.0
227223
# via
228224
# -c requirements/_base.txt
229225
# distributed
230-
psycopg2-binary==2.9.10
231-
# via
232-
# -c requirements/_base.txt
233-
# aiopg
234-
# sqlalchemy
235226
pytest==8.3.5
236227
# via
237228
# -r requirements/_test.in
@@ -299,7 +290,6 @@ sqlalchemy==1.4.54
299290
# -c requirements/../../../requirements/constraints.txt
300291
# -c requirements/_base.txt
301292
# -r requirements/_test.in
302-
# aiopg
303293
# alembic
304294
sqlalchemy2-stubs==0.0.2a38
305295
# via sqlalchemy

0 commit comments

Comments
 (0)