Skip to content

Commit b61359e

Browse files
committed
fix one test
1 parent 17f217c commit b61359e

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from models_library.products import ProductName
1414
from models_library.projects import ProjectAtDB, ProjectID
1515
from models_library.projects_nodes_io import NodeID
16+
from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan
1617
from simcore_postgres_database.models.comp_pipeline import StateType, comp_pipeline
1718
from simcore_postgres_database.models.comp_tasks import comp_tasks
1819
from simcore_postgres_database.models.products import products
@@ -69,25 +70,19 @@ def creator(**user_kwargs) -> dict[str, Any]:
6970
@pytest.fixture
7071
async def product_db(
7172
sqlalchemy_async_engine: AsyncEngine, product: dict[str, Any]
72-
) -> AsyncIterator[ProductName]:
73-
async with sqlalchemy_async_engine.begin() as con:
74-
result = await con.execute(
75-
products.insert().values(**product).returning(sa.literal_column("*"))
76-
)
77-
created_product = result.one()
78-
print(f"--> created product {created_product.name=}")
79-
yield created_product.name
80-
81-
async with sqlalchemy_async_engine.begin() as con:
82-
await con.execute(
83-
products.delete().where(products.c.name == created_product.name)
84-
)
85-
print(f"<-- deleted product {created_product.name=}")
73+
) -> AsyncIterator[dict[str, Any]]:
74+
async with insert_and_get_row_lifespan(
75+
sqlalchemy_async_engine,
76+
table=products,
77+
values=product,
78+
pk_col=products.c.name,
79+
) as created_product:
80+
yield created_product
8681

8782

8883
@pytest.fixture
8984
async def project(
90-
sqlalchemy_async_engine: AsyncEngine, faker: Faker, product_db: ProductName
85+
sqlalchemy_async_engine: AsyncEngine, faker: Faker, product_name: ProductName
9186
) -> AsyncIterator[Callable[..., Awaitable[ProjectAtDB]]]:
9287
created_project_ids: list[str] = []
9388

@@ -138,7 +133,7 @@ async def creator(
138133
await con.execute(
139134
projects_to_products.insert().values(
140135
project_uuid=f"{inserted_project.uuid}",
141-
product_name=product_db,
136+
product_name=product_name,
142137
)
143138
)
144139
print(f"--> created {inserted_project=}")

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_db_repositories_comp_runs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import datetime
1010
import random
1111
from collections.abc import Awaitable, Callable
12-
from typing import cast
12+
from typing import Any, cast
1313

1414
import arrow
1515
import pytest
@@ -56,6 +56,7 @@ async def test_get(
5656
fake_project_id: ProjectID,
5757
publish_project: Callable[[], Awaitable[PublishedProject]],
5858
create_comp_run: Callable[..., Awaitable[CompRunsAtDB]],
59+
product_db: dict[str, Any],
5960
):
6061
with pytest.raises(ComputationalRunNotFoundError):
6162
await CompRunsRepository(sqlalchemy_async_engine).get(
@@ -88,6 +89,7 @@ async def test_list(
8889
publish_project: Callable[[], Awaitable[PublishedProject]],
8990
run_metadata: RunMetadataDict,
9091
faker: Faker,
92+
product_db: dict[str, Any],
9193
):
9294
assert await CompRunsRepository(sqlalchemy_async_engine).list_() == []
9395

@@ -269,6 +271,7 @@ async def test_create(
269271
run_metadata: RunMetadataDict,
270272
faker: Faker,
271273
publish_project: Callable[[], Awaitable[PublishedProject]],
274+
product_db: dict[str, Any],
272275
):
273276
with pytest.raises(ProjectNotFoundError):
274277
await CompRunsRepository(sqlalchemy_async_engine).create(
@@ -331,6 +334,7 @@ async def test_update(
331334
run_metadata: RunMetadataDict,
332335
faker: Faker,
333336
publish_project: Callable[[], Awaitable[PublishedProject]],
337+
product_db: dict[str, Any],
334338
):
335339
# this updates nothing but also does not complain
336340
updated = await CompRunsRepository(sqlalchemy_async_engine).update(
@@ -371,6 +375,7 @@ async def test_set_run_result(
371375
run_metadata: RunMetadataDict,
372376
faker: Faker,
373377
publish_project: Callable[[], Awaitable[PublishedProject]],
378+
product_db: dict[str, Any],
374379
):
375380
published_project = await publish_project()
376381
created = await CompRunsRepository(sqlalchemy_async_engine).create(
@@ -419,6 +424,7 @@ async def test_mark_for_cancellation(
419424
run_metadata: RunMetadataDict,
420425
faker: Faker,
421426
publish_project: Callable[[], Awaitable[PublishedProject]],
427+
product_db: dict[str, Any],
422428
):
423429
published_project = await publish_project()
424430
created = await CompRunsRepository(sqlalchemy_async_engine).create(
@@ -451,6 +457,7 @@ async def test_mark_for_scheduling(
451457
run_metadata: RunMetadataDict,
452458
faker: Faker,
453459
publish_project: Callable[[], Awaitable[PublishedProject]],
460+
product_db: dict[str, Any],
454461
):
455462
published_project = await publish_project()
456463
created = await CompRunsRepository(sqlalchemy_async_engine).create(
@@ -485,6 +492,7 @@ async def test_mark_scheduling_done(
485492
run_metadata: RunMetadataDict,
486493
faker: Faker,
487494
publish_project: Callable[[], Awaitable[PublishedProject]],
495+
product_db: dict[str, Any],
488496
):
489497
published_project = await publish_project()
490498
created = await CompRunsRepository(sqlalchemy_async_engine).create(

0 commit comments

Comments
 (0)