1919 DBProjectNotFoundError ,
2020)
2121from simcore_postgres_database .utils_projects_nodes import ProjectNode
22+ from sqlalchemy .ext .asyncio import AsyncConnection
2223
2324
2425@pytest .fixture
@@ -47,6 +48,7 @@ async def fake_project(
4748)
4849async def test_set_project_custom_metadata (
4950 connection : SAConnection ,
51+ connection_factory : SAConnection | AsyncConnection ,
5052 create_fake_user : Callable [..., Awaitable [RowProxy ]],
5153 create_fake_project : Callable [..., Awaitable [RowProxy ]],
5254 faker : Faker ,
@@ -59,17 +61,19 @@ async def test_set_project_custom_metadata(
5961 random_project_uuid = faker .uuid4 (cast_to = None )
6062 assert isinstance (random_project_uuid , UUID )
6163 with pytest .raises (DBProjectNotFoundError ):
62- await utils_projects_metadata .get (connection , project_uuid = random_project_uuid )
64+ await utils_projects_metadata .get (
65+ connection_factory , project_uuid = random_project_uuid
66+ )
6367
6468 with pytest .raises (DBProjectNotFoundError ):
6569 await utils_projects_metadata .set_project_custom_metadata (
66- connection ,
70+ connection_factory ,
6771 project_uuid = random_project_uuid ,
6872 custom_metadata = user_metadata ,
6973 )
7074
7175 project_metadata = await utils_projects_metadata .get (
72- connection , project_uuid = project ["uuid" ]
76+ connection_factory , project_uuid = project ["uuid" ]
7377 )
7478 assert project_metadata is not None
7579 assert project_metadata .custom is None
@@ -79,7 +83,7 @@ async def test_set_project_custom_metadata(
7983 assert project_metadata .root_parent_node_id is None
8084
8185 got = await utils_projects_metadata .set_project_custom_metadata (
82- connection ,
86+ connection_factory ,
8387 project_uuid = project ["uuid" ],
8488 custom_metadata = user_metadata ,
8589 )
@@ -91,13 +95,13 @@ async def test_set_project_custom_metadata(
9195 assert user_metadata == got .custom
9296
9397 project_metadata = await utils_projects_metadata .get (
94- connection , project_uuid = project ["uuid" ]
98+ connection_factory , project_uuid = project ["uuid" ]
9599 )
96100 assert project_metadata is not None
97101 assert project_metadata == got
98102
99103 got_after_update = await utils_projects_metadata .set_project_custom_metadata (
100- connection ,
104+ connection_factory ,
101105 project_uuid = project ["uuid" ],
102106 custom_metadata = {},
103107 )
@@ -109,6 +113,7 @@ async def test_set_project_custom_metadata(
109113
110114async def test_set_project_ancestors_with_invalid_parents (
111115 connection : SAConnection ,
116+ connection_factory : SAConnection | AsyncConnection ,
112117 create_fake_user : Callable [..., Awaitable [RowProxy ]],
113118 create_fake_project : Callable [..., Awaitable [RowProxy ]],
114119 create_fake_projects_node : Callable [[uuid .UUID ], Awaitable [ProjectNode ]],
@@ -120,7 +125,7 @@ async def test_set_project_ancestors_with_invalid_parents(
120125
121126 # this is empty
122127 project_metadata = await utils_projects_metadata .get (
123- connection , project_uuid = project ["uuid" ]
128+ connection_factory , project_uuid = project ["uuid" ]
124129 )
125130 assert project_metadata is not None
126131 assert project_metadata .custom is None
@@ -137,7 +142,7 @@ async def test_set_project_ancestors_with_invalid_parents(
137142 # invalid project
138143 with pytest .raises (DBProjectNotFoundError ):
139144 await utils_projects_metadata .set_project_ancestors (
140- connection ,
145+ connection_factory ,
141146 project_uuid = random_project_uuid ,
142147 parent_project_uuid = None ,
143148 parent_node_id = None ,
@@ -146,14 +151,14 @@ async def test_set_project_ancestors_with_invalid_parents(
146151 # test invalid combinations
147152 with pytest .raises (DBProjectInvalidAncestorsError ):
148153 await utils_projects_metadata .set_project_ancestors (
149- connection ,
154+ connection_factory ,
150155 project_uuid = project ["uuid" ],
151156 parent_project_uuid = random_project_uuid ,
152157 parent_node_id = None ,
153158 )
154159 with pytest .raises (DBProjectInvalidAncestorsError ):
155160 await utils_projects_metadata .set_project_ancestors (
156- connection ,
161+ connection_factory ,
157162 project_uuid = project ["uuid" ],
158163 parent_project_uuid = None ,
159164 parent_node_id = random_node_id ,
@@ -162,7 +167,7 @@ async def test_set_project_ancestors_with_invalid_parents(
162167 # valid combination with invalid project/node
163168 with pytest .raises (DBProjectInvalidParentProjectError ):
164169 await utils_projects_metadata .set_project_ancestors (
165- connection ,
170+ connection_factory ,
166171 project_uuid = project ["uuid" ],
167172 parent_project_uuid = random_project_uuid ,
168173 parent_node_id = random_node_id ,
@@ -171,15 +176,15 @@ async def test_set_project_ancestors_with_invalid_parents(
171176 # these would make it a parent of itself which is forbiden
172177 with pytest .raises (DBProjectInvalidAncestorsError ):
173178 await utils_projects_metadata .set_project_ancestors (
174- connection ,
179+ connection_factory ,
175180 project_uuid = project ["uuid" ],
176181 parent_project_uuid = project ["uuid" ],
177182 parent_node_id = random_node_id ,
178183 )
179184
180185 with pytest .raises (DBProjectInvalidAncestorsError ):
181186 await utils_projects_metadata .set_project_ancestors (
182- connection ,
187+ connection_factory ,
183188 project_uuid = project ["uuid" ],
184189 parent_project_uuid = project ["uuid" ],
185190 parent_node_id = project_node .node_id ,
@@ -190,15 +195,15 @@ async def test_set_project_ancestors_with_invalid_parents(
190195 another_project_node = await create_fake_projects_node (another_project ["uuid" ])
191196 with pytest .raises (DBProjectInvalidParentNodeError ):
192197 await utils_projects_metadata .set_project_ancestors (
193- connection ,
198+ connection_factory ,
194199 project_uuid = another_project ["uuid" ],
195200 parent_project_uuid = project ["uuid" ],
196201 parent_node_id = random_node_id ,
197202 )
198203
199204 with pytest .raises (DBProjectInvalidParentProjectError ):
200205 await utils_projects_metadata .set_project_ancestors (
201- connection ,
206+ connection_factory ,
202207 project_uuid = another_project ["uuid" ],
203208 parent_project_uuid = random_project_uuid ,
204209 parent_node_id = project_node .node_id ,
@@ -208,15 +213,15 @@ async def test_set_project_ancestors_with_invalid_parents(
208213 yet_another_project = await create_fake_project (connection , user , hidden = False )
209214 with pytest .raises (DBProjectInvalidParentNodeError ):
210215 await utils_projects_metadata .set_project_ancestors (
211- connection ,
216+ connection_factory ,
212217 project_uuid = yet_another_project ["uuid" ],
213218 parent_project_uuid = project ["uuid" ],
214219 parent_node_id = another_project_node .node_id ,
215220 )
216221
217222 with pytest .raises (DBProjectInvalidParentNodeError ):
218223 await utils_projects_metadata .set_project_ancestors (
219- connection ,
224+ connection_factory ,
220225 project_uuid = yet_another_project ["uuid" ],
221226 parent_project_uuid = another_project ["uuid" ],
222227 parent_node_id = project_node .node_id ,
@@ -225,6 +230,7 @@ async def test_set_project_ancestors_with_invalid_parents(
225230
226231async def test_set_project_ancestors (
227232 connection : SAConnection ,
233+ connection_factory : SAConnection | AsyncConnection ,
228234 create_fake_user : Callable [..., Awaitable [RowProxy ]],
229235 create_fake_project : Callable [..., Awaitable [RowProxy ]],
230236 create_fake_projects_node : Callable [[uuid .UUID ], Awaitable [ProjectNode ]],
@@ -244,7 +250,7 @@ async def test_set_project_ancestors(
244250
245251 # set ancestry, first the parents
246252 updated_parent_metadata = await utils_projects_metadata .set_project_ancestors (
247- connection ,
253+ connection_factory ,
248254 project_uuid = parent_project ["uuid" ],
249255 parent_project_uuid = grand_parent_project ["uuid" ],
250256 parent_node_id = grand_parent_node .node_id ,
@@ -260,7 +266,7 @@ async def test_set_project_ancestors(
260266
261267 # then the child
262268 updated_child_metadata = await utils_projects_metadata .set_project_ancestors (
263- connection ,
269+ connection_factory ,
264270 project_uuid = child_project ["uuid" ],
265271 parent_project_uuid = parent_project ["uuid" ],
266272 parent_node_id = parent_node .node_id ,
@@ -276,13 +282,13 @@ async def test_set_project_ancestors(
276282
277283 # check properly updated
278284 returned_project_metadata = await utils_projects_metadata .get (
279- connection , project_uuid = child_project ["uuid" ]
285+ connection_factory , project_uuid = child_project ["uuid" ]
280286 )
281287 assert returned_project_metadata == updated_child_metadata
282288
283289 # remove the child
284290 updated_child_metadata = await utils_projects_metadata .set_project_ancestors (
285- connection ,
291+ connection_factory ,
286292 project_uuid = child_project ["uuid" ],
287293 parent_project_uuid = None ,
288294 parent_node_id = None ,
@@ -294,7 +300,7 @@ async def test_set_project_ancestors(
294300
295301
296302async def _create_child_project (
297- connection : SAConnection ,
303+ connection_factory : SAConnection | AsyncConnection ,
298304 user : RowProxy ,
299305 create_fake_project : Callable [..., Awaitable [RowProxy ]],
300306 create_fake_projects_node : Callable [[uuid .UUID ], Awaitable [ProjectNode ]],
@@ -305,7 +311,7 @@ async def _create_child_project(
305311 node = await create_fake_projects_node (project ["uuid" ])
306312 if parent_project and parent_node :
307313 await utils_projects_metadata .set_project_ancestors (
308- connection ,
314+ connection_factory ,
309315 project_uuid = project ["uuid" ],
310316 parent_project_uuid = parent_project ["uuid" ],
311317 parent_node_id = parent_node .node_id ,
@@ -316,6 +322,7 @@ async def _create_child_project(
316322@pytest .fixture
317323async def create_projects_genealogy (
318324 connection : SAConnection ,
325+ connection_factory : SAConnection | AsyncConnection ,
319326 create_fake_project : Callable [..., Awaitable [RowProxy ]],
320327 create_fake_projects_node : Callable [[uuid .UUID ], Awaitable [ProjectNode ]],
321328) -> Callable [[RowProxy ], Awaitable [list [tuple [RowProxy , ProjectNode ]]]]:
@@ -328,7 +335,7 @@ async def _(user: RowProxy) -> list[tuple[RowProxy, ProjectNode]]:
328335
329336 for _ in range (13 ):
330337 child_project , child_node = await _create_child_project (
331- connection ,
338+ connection_factory ,
332339 user ,
333340 create_fake_project ,
334341 create_fake_projects_node ,
@@ -346,6 +353,7 @@ async def _(user: RowProxy) -> list[tuple[RowProxy, ProjectNode]]:
346353
347354async def test_not_implemented_use_cases (
348355 connection : SAConnection ,
356+ connection_factory : SAConnection | AsyncConnection ,
349357 create_fake_user : Callable [..., Awaitable [RowProxy ]],
350358 create_fake_project : Callable [..., Awaitable [RowProxy ]],
351359 create_fake_projects_node : Callable [[uuid .UUID ], Awaitable [ProjectNode ]],
@@ -367,7 +375,7 @@ async def test_not_implemented_use_cases(
367375
368376 with pytest .raises (NotImplementedError ):
369377 await utils_projects_metadata .set_project_ancestors (
370- connection ,
378+ connection_factory ,
371379 project_uuid = ancestors [0 ][0 ]["uuid" ],
372380 parent_project_uuid = missing_parent_project ["uuid" ],
373381 parent_node_id = missing_parent_node .node_id ,
@@ -376,7 +384,7 @@ async def test_not_implemented_use_cases(
376384 # modifying a parent-child relationship in the middle of the genealogy is also not implemented
377385 with pytest .raises (NotImplementedError ):
378386 await utils_projects_metadata .set_project_ancestors (
379- connection ,
387+ connection_factory ,
380388 project_uuid = ancestors [3 ][0 ]["uuid" ],
381389 parent_project_uuid = missing_parent_project ["uuid" ],
382390 parent_node_id = missing_parent_node .node_id ,
0 commit comments