Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/postgres-database/tests/test_comp_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import asyncio
import json
from collections.abc import AsyncIterator

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


@pytest.fixture()
async def db_notification_queue(db_connection: SAConnection) -> asyncio.Queue:
async def db_notification_queue(
db_connection: SAConnection,
) -> AsyncIterator[asyncio.Queue]:
listen_query = f"LISTEN {DB_CHANNEL_NAME};"
await db_connection.execute(listen_query)
notifications_queue: asyncio.Queue = db_connection.connection.notifies
Expand Down
21 changes: 12 additions & 9 deletions packages/pytest-simcore/src/pytest_simcore/db_entries_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any
from uuid import uuid4

import aiopg.sa
import pytest
import sqlalchemy as sa
from faker import Faker
Expand All @@ -20,6 +19,7 @@
ProjectNodeCreate,
ProjectNodesRepo,
)
from sqlalchemy.ext.asyncio import AsyncEngine


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

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

Expand All @@ -86,17 +86,22 @@ async def creator(
"workbench": {},
}
project_config.update(**project_overrides)
async with aiopg_engine.acquire() as con, con.begin():
async with sqlalchemy_async_engine.connect() as con, con.begin():
result = await con.execute(
projects.insert()
.values(**project_config)
.returning(sa.literal_column("*"))
)

inserted_project = ProjectAtDB.model_validate(await result.first())
inserted_project = ProjectAtDB.model_validate(result.one())
project_nodes_repo = ProjectNodesRepo(project_uuid=project_uuid)
# NOTE: currently no resources is passed until it becomes necessary
default_node_config = {"required_resources": {}, "key": faker.pystr(), "version": faker.pystr(), "label": faker.pystr()}
default_node_config = {
"required_resources": {},
"key": faker.pystr(),
"version": faker.pystr(),
"label": faker.pystr(),
}
if project_nodes_overrides:
default_node_config.update(project_nodes_overrides)
await project_nodes_repo.add(
Expand All @@ -113,17 +118,15 @@ async def creator(
yield creator

# cleanup
async with aiopg_engine.acquire() as con:
async with sqlalchemy_async_engine.begin() as con:
await con.execute(
projects.delete().where(projects.c.uuid.in_(created_project_ids))
)
print(f"<-- delete projects {created_project_ids=}")


@pytest.fixture
def pipeline(
postgres_db: sa.engine.Engine,
) -> Iterator[Callable[..., dict[str, Any]]]:
def pipeline(postgres_db: sa.engine.Engine) -> Iterator[Callable[..., dict[str, Any]]]:
created_pipeline_ids: list[str] = []

def creator(**pipeline_kwargs) -> dict[str, Any]:
Expand Down
11 changes: 9 additions & 2 deletions packages/pytest-simcore/src/pytest_simcore/postgres_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
# pylint: disable=unused-variable

import json
import warnings
from collections.abc import AsyncIterator, Iterator
from typing import Final

import docker
import pytest
import sqlalchemy as sa
import tenacity
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
from pytest_simcore.helpers.typing_env import EnvVarsDict
from sqlalchemy.ext.asyncio import AsyncEngine
from tenacity.stop import stop_after_delay
from tenacity.wait import wait_fixed

from .helpers.docker import get_service_published_port
from .helpers.host import get_localhost_ip
from .helpers.monkeypatch_envs import setenvs_from_dict
from .helpers.postgres_tools import PostgresTestConfig, migrated_pg_tables_context
from .helpers.typing_env import EnvVarsDict

_TEMPLATE_DB_TO_RESTORE = "template_simcore_db"

Expand Down Expand Up @@ -212,6 +213,12 @@ async def aiopg_engine(

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

warnings.warn(
"The 'aiopg_engine' fixture is deprecated and will be removed in a future release. "
"Please use 'asyncpg_engine' fixture instead.",
DeprecationWarning,
stacklevel=2,
)
yield engine

if engine:
Expand Down
1 change: 0 additions & 1 deletion services/director-v2/requirements/_test.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

aio_pika
aioboto3
aiopg[sa]
alembic # migration due to pytest_simcore.postgres_service2
asgi_lifespan
async-asgi-testclient # replacement for fastapi.testclient.TestClient [see b) below]
Expand Down
10 changes: 0 additions & 10 deletions services/director-v2/requirements/_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ aiohttp==3.11.13
# aiobotocore
aioitertools==0.12.0
# via aiobotocore
aiopg==1.4.0
# via -r requirements/_test.in
aiormq==6.8.1
# via
# -c requirements/_base.txt
Expand All @@ -43,8 +41,6 @@ asgi-lifespan==2.1.0
# via -r requirements/_test.in
async-asgi-testclient==1.4.11
# via -r requirements/_test.in
async-timeout==4.0.3
# via aiopg
attrs==25.1.0
# via
# -c requirements/_base.txt
Expand Down Expand Up @@ -227,11 +223,6 @@ psutil==6.1.0
# via
# -c requirements/_base.txt
# distributed
psycopg2-binary==2.9.10
# via
# -c requirements/_base.txt
# aiopg
# sqlalchemy
pytest==8.3.5
# via
# -r requirements/_test.in
Expand Down Expand Up @@ -299,7 +290,6 @@ sqlalchemy==1.4.54
# -c requirements/../../../requirements/constraints.txt
# -c requirements/_base.txt
# -r requirements/_test.in
# aiopg
# alembic
sqlalchemy2-stubs==0.0.2a38
# via sqlalchemy
Expand Down
Loading