Skip to content

Commit 604b9c1

Browse files
committed
add some more use cases
1 parent 3f3f10a commit 604b9c1

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

services/storage/tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,22 @@ async def _create_content(
561561

562562
# Create subdirectories
563563
s3_base_path = Path(f"{project_id}") / f"{node_id}" / dir_name
564-
s3_subdirs = [s3_base_path / f"sub-dir-{i}" for i in range(subdir_count)]
564+
# NOTE: add a space in the sub directory
565+
s3_subdirs = [
566+
s3_base_path / f"sub-dir_ect ory-{i}" for i in range(subdir_count)
567+
]
565568
# Randomly distribute files across subdirectories
566569
selected_subdirs = random.choices(s3_subdirs, k=file_count) # noqa: S311
567570
# Upload to S3
568571
with log_context(
569572
logging.INFO,
570573
msg=f"Uploading {file_count} files to S3 (each {file_size_in_dir.human_readable()}, total: {ByteSize(file_count * file_size_in_dir).human_readable()})",
571574
):
575+
# we ensure the file name contain a space
576+
def _file_name_with_space():
577+
file_name = faker.unique.file_name()
578+
return f"{file_name[:1]} {file_name[1:]}"
579+
572580
results = await asyncio.gather(
573581
*(
574582
_upload_file_to_s3(
@@ -577,7 +585,7 @@ async def _create_content(
577585
s3_bucket=storage_s3_bucket,
578586
local_file=local_file,
579587
file_id=TypeAdapter(SimcoreS3FileID).validate_python(
580-
f"{selected_subdir / faker.unique.file_name()}"
588+
f"{selected_subdir / _file_name_with_space()}"
581589
),
582590
)
583591
for selected_subdir in selected_subdirs

services/storage/tests/unit/test_handlers_paths.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ async def test_list_paths(
371371
ProjectWithFilesParams(
372372
num_nodes=1,
373373
allowed_file_sizes=(TypeAdapter(ByteSize).validate_python("0b"),),
374-
workspace_files_count=0,
374+
workspace_files_count=10,
375375
)
376376
],
377377
ids=str,
@@ -449,3 +449,38 @@ async def test_list_paths_with_display_name_containing_slashes(
449449
) / quote(
450450
node_name_with_non_ascii, safe=""
451451
), "display path parts should be url encoded"
452+
453+
# ls in the node workspace
454+
selected_node_id = NodeID(random.choice(list(project["workbench"]))) # noqa: S311
455+
selected_node_s3_keys = [
456+
Path(s3_object_id) for s3_object_id in list_of_files[selected_node_id]
457+
]
458+
workspace_file_filter = file_filter / f"{selected_node_id}" / "workspace"
459+
expected_paths = _filter_and_group_paths_one_level_deeper(
460+
selected_node_s3_keys, workspace_file_filter
461+
)
462+
await _assert_list_paths(
463+
initialized_app,
464+
client,
465+
location_id,
466+
user_id,
467+
file_filter=workspace_file_filter,
468+
expected_paths=expected_paths,
469+
check_total=False,
470+
)
471+
472+
# ls in until we get to some files
473+
while selected_subfolders := [p for p in expected_paths if p[1] is False]:
474+
selected_path_filter = random.choice(selected_subfolders) # noqa: S311
475+
expected_paths = _filter_and_group_paths_one_level_deeper(
476+
selected_node_s3_keys, selected_path_filter[0]
477+
)
478+
await _assert_list_paths(
479+
initialized_app,
480+
client,
481+
location_id,
482+
user_id,
483+
file_filter=selected_path_filter[0],
484+
expected_paths=expected_paths,
485+
check_total=False,
486+
)

0 commit comments

Comments
 (0)