Skip to content

Commit 5bce45d

Browse files
fix: fixtures still using workbench
1 parent e33be86 commit 5bce45d

File tree

3 files changed

+56
-30
lines changed

3 files changed

+56
-30
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ async def _() -> None:
215215
@pytest.fixture
216216
async def create_project_node(
217217
user_id: UserID, sqlalchemy_async_engine: AsyncEngine, faker: Faker
218-
) -> Callable[..., Awaitable[NodeID]]:
218+
) -> Callable[..., Awaitable[tuple[NodeID, dict[str, Any]]]]:
219219
async def _creator(
220220
project_id: ProjectID, node_id: NodeID | None = None, **kwargs
221-
) -> NodeID:
221+
) -> tuple[NodeID, dict[str, Any]]:
222222
async with sqlalchemy_async_engine.begin() as conn:
223223
new_node_id = node_id or NodeID(faker.uuid4())
224224
node_values = {
@@ -227,13 +227,16 @@ async def _creator(
227227
"label": "pytest_fake_node",
228228
}
229229
node_values.update(**kwargs)
230-
await conn.execute(
231-
projects_nodes.insert().values(
230+
result = await conn.execute(
231+
projects_nodes.insert()
232+
.values(
232233
node_id=f"{new_node_id}",
233234
project_uuid=f"{project_id}",
234235
**node_values,
235236
)
237+
.returning(sa.literal_column("*"))
236238
)
237-
return new_node_id
239+
row = result.one()
240+
return new_node_id, row._asdict()
238241

239242
return _creator

services/storage/tests/conftest.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,13 @@ async def client(
259259

260260
@pytest.fixture
261261
async def node_id(
262-
project_id: ProjectID, create_project_node: Callable[[ProjectID], Awaitable[NodeID]]
262+
project_id: ProjectID,
263+
create_project_node: Callable[
264+
[ProjectID], Awaitable[tuple[NodeID, dict[str, Any]]]
265+
],
263266
) -> NodeID:
264-
return await create_project_node(project_id)
267+
node_id, _ = await create_project_node(project_id)
268+
return node_id
265269

266270

267271
@pytest.fixture
@@ -784,7 +788,7 @@ async def _upload_folder_task(
784788
async def random_project_with_files(
785789
sqlalchemy_async_engine: AsyncEngine,
786790
create_project: Callable[..., Awaitable[dict[str, Any]]],
787-
create_project_node: Callable[..., Awaitable[NodeID]],
791+
create_project_node: Callable[..., Awaitable[tuple[NodeID, dict[str, Any]]]],
788792
create_simcore_file_id: Callable[
789793
[ProjectID, NodeID, str, Path | None], SimcoreS3FileID
790794
],
@@ -798,17 +802,28 @@ async def random_project_with_files(
798802
upload_file: Callable[..., Awaitable[tuple[Path, SimcoreS3FileID]]],
799803
) -> Callable[
800804
[ProjectWithFilesParams],
801-
Awaitable[tuple[dict[str, Any], dict[NodeID, dict[SimcoreS3FileID, FileIDDict]]]],
805+
Awaitable[
806+
tuple[
807+
dict[str, Any],
808+
dict[NodeID, dict[str, Any]],
809+
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
810+
]
811+
],
802812
]:
803813
async def _creator(
804814
project_params: ProjectWithFilesParams,
805-
) -> tuple[dict[str, Any], dict[NodeID, dict[SimcoreS3FileID, FileIDDict]]]:
815+
) -> tuple[
816+
dict[str, Any],
817+
dict[NodeID, dict[str, Any]],
818+
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
819+
]:
806820
assert len(project_params.allowed_file_sizes) == len(
807821
project_params.allowed_file_checksums
808822
)
809823
project = await create_project(name="random-project")
810824
node_to_files_mapping: dict[NodeID, dict[SimcoreS3FileID, FileIDDict]] = {}
811825
upload_tasks = []
826+
nodes: dict[NodeID, dict[str, Any]] = {}
812827
for _ in range(project_params.num_nodes):
813828
# Create a node with outputs (files and others)
814829
project_id = ProjectID(project["uuid"])
@@ -818,7 +833,7 @@ async def _creator(
818833
output3_file_id = create_simcore_file_id(
819834
project_id, node_id, output3_file_name, Path("outputs/output_3")
820835
)
821-
created_node_id = await create_project_node(
836+
created_node_id, created_node = await create_project_node(
822837
ProjectID(project["uuid"]),
823838
node_id,
824839
outputs={
@@ -828,6 +843,7 @@ async def _creator(
828843
},
829844
)
830845
assert created_node_id == node_id
846+
nodes[created_node_id] = created_node
831847

832848
upload_tasks.append(
833849
_upload_one_file_task(
@@ -878,7 +894,7 @@ async def _creator(
878894
node_to_files_mapping[node_id][file_id] = file_dict
879895

880896
project = await get_updated_project(sqlalchemy_async_engine, project["uuid"])
881-
return project, node_to_files_mapping
897+
return project, nodes, node_to_files_mapping
882898

883899
return _creator
884900

@@ -933,7 +949,7 @@ async def output_file(
933949
yield file
934950

935951
async with sqlalchemy_async_engine.begin() as conn:
936-
result = await conn.execute(
952+
await conn.execute(
937953
file_meta_data.delete().where(file_meta_data.c.file_id == row.file_id)
938954
)
939955

services/storage/tests/unit/test_handlers_paths.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ async def test_list_paths_pagination(
157157
user_id: UserID,
158158
with_random_project_with_files: tuple[
159159
dict[str, Any],
160+
dict[NodeID, dict[str, Any]],
160161
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
161162
],
162163
):
163-
project, list_of_files = with_random_project_with_files
164-
num_nodes = len(list(project["workbench"]))
164+
project, nodes, list_of_files = with_random_project_with_files
165165

166166
# ls the nodes (DB-based)
167167
file_filter = Path(project["uuid"])
168168
expected_paths = sorted(
169-
((file_filter / node_key, False) for node_key in project["workbench"]),
169+
((file_filter / f"{node_id}", False) for node_id in nodes),
170170
key=lambda x: x[0],
171171
)
172172
await _assert_list_paths(
@@ -176,12 +176,12 @@ async def test_list_paths_pagination(
176176
user_id,
177177
file_filter=file_filter,
178178
expected_paths=expected_paths,
179-
limit=int(num_nodes / 2 + 0.5),
179+
limit=int(len(nodes) / 2 + 0.5),
180180
)
181181

182182
# ls in the workspace (S3-based)
183183
# ls in the workspace
184-
selected_node_id = NodeID(random.choice(list(project["workbench"]))) # noqa: S311
184+
selected_node_id = random.choice(list(nodes.keys())) # noqa: S311
185185
selected_node_s3_keys = [
186186
Path(s3_object_id) for s3_object_id in list_of_files[selected_node_id]
187187
]
@@ -240,11 +240,12 @@ async def test_list_paths_pagination_large_page(
240240
user_id: UserID,
241241
with_random_project_with_files: tuple[
242242
dict[str, Any],
243+
dict[NodeID, dict[str, Any]],
243244
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
244245
],
245246
):
246-
project, list_of_files = with_random_project_with_files
247-
selected_node_id = NodeID(random.choice(list(project["workbench"]))) # noqa: S311
247+
project, nodes, list_of_files = with_random_project_with_files
248+
selected_node_id = random.choice(list(nodes.keys())) # noqa: S311
248249
selected_node_s3_keys = [
249250
Path(s3_object_id) for s3_object_id in list_of_files[selected_node_id]
250251
]
@@ -292,7 +293,11 @@ async def test_list_paths(
292293
random_project_with_files: Callable[
293294
[ProjectWithFilesParams],
294295
Awaitable[
295-
tuple[dict[str, Any], dict[NodeID, dict[SimcoreS3FileID, FileIDDict]]]
296+
tuple[
297+
dict[str, Any],
298+
dict[NodeID, dict[str, Any]],
299+
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
300+
]
296301
],
297302
],
298303
project_params: ProjectWithFilesParams,
@@ -305,7 +310,10 @@ async def test_list_paths(
305310

306311
# ls root returns our projects
307312
expected_paths = sorted(
308-
((Path(f"{prj_db['uuid']}"), False) for prj_db, _ in project_to_files_mapping),
313+
(
314+
(Path(f"{prj_db['uuid']}"), False)
315+
for prj_db, _, _ in project_to_files_mapping
316+
),
309317
key=lambda x: x[0],
310318
)
311319
await _assert_list_paths(
@@ -318,9 +326,9 @@ async def test_list_paths(
318326
)
319327

320328
# ls with only some part of the path should return only the projects that match
321-
selected_project, selected_project_files = random.choice( # noqa: S311
329+
selected_project, selected_nodes, selected_project_files = random.choice(
322330
project_to_files_mapping
323-
)
331+
) # noqa: S311
324332
partial_file_filter = Path(
325333
selected_project["uuid"][: len(selected_project["uuid"]) // 2]
326334
)
@@ -340,7 +348,7 @@ async def test_list_paths(
340348
# now we ls inside one of the projects returns the nodes
341349
file_filter = Path(selected_project["uuid"])
342350
expected_paths = sorted(
343-
((file_filter / node_key, False) for node_key in selected_project["workbench"]),
351+
((file_filter / f"{node_id}", False) for node_id in selected_nodes),
344352
key=lambda x: x[0],
345353
)
346354
await _assert_list_paths(
@@ -353,9 +361,7 @@ async def test_list_paths(
353361
)
354362

355363
# now we ls in one of the nodes
356-
selected_node_id = NodeID(
357-
random.choice(list(selected_project["workbench"])) # noqa: S311
358-
)
364+
selected_node_id = random.choice(list(selected_nodes)) # noqa: S311
359365
selected_node_s3_keys = [
360366
Path(s3_object_id) for s3_object_id in selected_project_files[selected_node_id]
361367
]
@@ -623,14 +629,15 @@ async def test_path_compute_size(
623629
user_id: UserID,
624630
with_random_project_with_files: tuple[
625631
dict[str, Any],
632+
dict[NodeID, dict[str, Any]],
626633
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
627634
],
628635
project_params: ProjectWithFilesParams,
629636
):
630637
assert (
631638
len(project_params.allowed_file_sizes) == 1
632639
), "test preconditions are not filled! allowed file sizes should have only 1 option for this test"
633-
project, list_of_files = with_random_project_with_files
640+
project, nodes, list_of_files = with_random_project_with_files
634641

635642
total_num_files = sum(
636643
len(files_in_node) for files_in_node in list_of_files.values()
@@ -649,7 +656,7 @@ async def test_path_compute_size(
649656
)
650657

651658
# get size of one of the nodes
652-
selected_node_id = NodeID(random.choice(list(project["workbench"]))) # noqa: S311
659+
selected_node_id = random.choice(list(nodes.keys())) # noqa: S311
653660
path = Path(project["uuid"]) / f"{selected_node_id}"
654661
selected_node_s3_keys = [
655662
Path(s3_object_id) for s3_object_id in list_of_files[selected_node_id]

0 commit comments

Comments
 (0)