Skip to content

Commit c209c6b

Browse files
committed
fixes tests modules
1 parent 77d26ec commit c209c6b

File tree

2 files changed

+78
-45
lines changed

2 files changed

+78
-45
lines changed

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

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# pylint:disable=no-value-for-parameter
55

66
import contextlib
7+
import logging
78
from collections.abc import AsyncIterator, Awaitable, Callable, Iterator
89
from typing import Any
910
from uuid import uuid4
@@ -14,6 +15,7 @@
1415
from models_library.products import ProductName
1516
from models_library.projects import ProjectAtDB, ProjectID
1617
from models_library.projects_nodes_io import NodeID
18+
from pytest_simcore.helpers.logging_tools import log_context
1719
from simcore_postgres_database.models.comp_pipeline import StateType, comp_pipeline
1820
from simcore_postgres_database.models.comp_tasks import comp_tasks
1921
from simcore_postgres_database.models.products import products
@@ -30,6 +32,8 @@
3032
from .helpers.postgres_tools import insert_and_get_row_lifespan
3133
from .helpers.postgres_users import sync_insert_and_get_user_and_secrets_lifespan
3234

35+
_logger = logging.getLogger(__name__)
36+
3337

3438
@pytest.fixture()
3539
def create_registered_user(
@@ -89,52 +93,65 @@ async def _(
8993
**project_overrides,
9094
) -> ProjectAtDB:
9195
project_uuid = uuid4()
92-
print(f"Created new project with uuid={project_uuid}")
93-
project_config = {
94-
"uuid": f"{project_uuid}",
95-
"name": faker.name(),
96-
"type": ProjectType.STANDARD.name,
97-
"description": faker.text(),
98-
"prj_owner": user["id"],
99-
"access_rights": {"1": {"read": True, "write": True, "delete": True}},
100-
"thumbnail": "",
101-
"workbench": {},
102-
}
103-
project_config.update(**project_overrides)
104-
async with sqlalchemy_async_engine.connect() as con, con.begin():
105-
result = await con.execute(
106-
projects.insert()
107-
.values(**project_config)
108-
.returning(sa.literal_column("*"))
109-
)
110-
111-
inserted_project = ProjectAtDB.model_validate(result.one())
112-
project_nodes_repo = ProjectNodesRepo(project_uuid=project_uuid)
113-
# NOTE: currently no resources is passed until it becomes necessary
114-
default_node_config = {
115-
"required_resources": {},
116-
"key": faker.pystr(),
117-
"version": faker.pystr(),
118-
"label": faker.pystr(),
96+
with log_context(
97+
logging.INFO,
98+
"Creating new project with uuid=%s",
99+
project_uuid,
100+
logger=_logger,
101+
) as log_ctx:
102+
103+
default_project_config = {
104+
"uuid": f"{project_uuid}",
105+
"name": faker.name(),
106+
"type": ProjectType.STANDARD.name,
107+
"description": faker.text(),
108+
"prj_owner": user["id"],
109+
"access_rights": {"1": {"read": True, "write": True, "delete": True}},
110+
"thumbnail": "",
119111
}
120-
if project_nodes_overrides:
121-
default_node_config.update(project_nodes_overrides)
122-
await project_nodes_repo.add(
123-
con,
124-
nodes=[
125-
ProjectNodeCreate(node_id=NodeID(node_id), **default_node_config)
126-
for node_id in inserted_project.workbench
127-
],
128-
)
129-
await con.execute(
130-
projects_to_products.insert().values(
131-
project_uuid=f"{inserted_project.uuid}",
132-
product_name=product_name,
112+
default_project_config.update(**project_overrides)
113+
project_workbench = default_project_config.pop("workbench", {})
114+
115+
async with sqlalchemy_async_engine.connect() as con, con.begin():
116+
result = await con.execute(
117+
projects.insert()
118+
.values(**default_project_config)
119+
.returning(sa.literal_column("*"))
133120
)
134-
)
135-
print(f"--> created {inserted_project=}")
136-
created_project_ids.append(f"{inserted_project.uuid}")
137-
return inserted_project
121+
122+
inserted_project = ProjectAtDB.model_validate(
123+
{**dict(result.one()._asdict()), "workbench": project_workbench}
124+
)
125+
126+
project_nodes_repo = ProjectNodesRepo(project_uuid=project_uuid)
127+
# NOTE: currently no resources is passed until it becomes necessary
128+
default_node_config = {
129+
"required_resources": {},
130+
"key": faker.pystr(),
131+
"version": faker.pystr(),
132+
"label": faker.pystr(),
133+
}
134+
if project_nodes_overrides:
135+
default_node_config.update(project_nodes_overrides)
136+
137+
await project_nodes_repo.add(
138+
con,
139+
nodes=[
140+
ProjectNodeCreate(
141+
node_id=NodeID(node_id), **default_node_config
142+
)
143+
for node_id in inserted_project.workbench
144+
],
145+
)
146+
await con.execute(
147+
projects_to_products.insert().values(
148+
project_uuid=f"{inserted_project.uuid}",
149+
product_name=product_name,
150+
)
151+
)
152+
log_ctx.logger.info("Created project %s", inserted_project)
153+
created_project_ids.append(f"{inserted_project.uuid}")
154+
return inserted_project
138155

139156
yield _
140157

@@ -143,7 +160,7 @@ async def _(
143160
await con.execute(
144161
projects.delete().where(projects.c.uuid.in_(created_project_ids))
145162
)
146-
print(f"<-- delete projects {created_project_ids=}")
163+
_logger.info("<-- delete projects %s", created_project_ids)
147164

148165

149166
@pytest.fixture

services/director-v2/src/simcore_service_director_v2/modules/db/tables.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
from simcore_postgres_database.models.comp_pipeline import StateType, comp_pipeline
2+
from simcore_postgres_database.models.comp_run_snapshot_tasks import (
3+
comp_run_snapshot_tasks,
4+
)
5+
from simcore_postgres_database.models.comp_runs import comp_runs
6+
from simcore_postgres_database.models.comp_tasks import NodeClass, comp_tasks
7+
from simcore_postgres_database.models.groups import user_to_groups
8+
from simcore_postgres_database.models.groups_extra_properties import (
9+
groups_extra_properties,
10+
)
11+
from simcore_postgres_database.models.projects import ProjectType, projects
12+
from simcore_postgres_database.models.projects_networks import projects_networks
13+
from simcore_postgres_database.models.projects_nodes import projects_nodes
14+
115
__all__: tuple[str, ...] = (
216
"NodeClass",
317
"ProjectType",
@@ -12,3 +26,5 @@
1226
"projects_nodes",
1327
"user_to_groups",
1428
)
29+
30+
# nopycln: file

0 commit comments

Comments
 (0)