44# pylint:disable=no-value-for-parameter
55
66import contextlib
7+ import logging
78from collections .abc import AsyncIterator , Awaitable , Callable , Iterator
89from typing import Any
910from uuid import uuid4
1415from models_library .products import ProductName
1516from models_library .projects import ProjectAtDB , ProjectID
1617from models_library .projects_nodes_io import NodeID
18+ from pytest_simcore .helpers .logging_tools import log_context
1719from simcore_postgres_database .models .comp_pipeline import StateType , comp_pipeline
1820from simcore_postgres_database .models .comp_tasks import comp_tasks
1921from simcore_postgres_database .models .products import products
3032from .helpers .postgres_tools import insert_and_get_row_lifespan
3133from .helpers .postgres_users import sync_insert_and_get_user_and_secrets_lifespan
3234
35+ _logger = logging .getLogger (__name__ )
36+
3337
3438@pytest .fixture ()
3539def 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
0 commit comments