Skip to content

Commit 3889204

Browse files
committed
add some more use cases
1 parent 1d714f9 commit 3889204

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
@@ -562,14 +562,22 @@ async def _create_content(
562562

563563
# Create subdirectories
564564
s3_base_path = Path(f"{project_id}") / f"{node_id}" / dir_name
565-
s3_subdirs = [s3_base_path / f"sub-dir-{i}" for i in range(subdir_count)]
565+
# NOTE: add a space in the sub directory
566+
s3_subdirs = [
567+
s3_base_path / f"sub-dir_ect ory-{i}" for i in range(subdir_count)
568+
]
566569
# Randomly distribute files across subdirectories
567570
selected_subdirs = random.choices(s3_subdirs, k=file_count) # noqa: S311
568571
# Upload to S3
569572
with log_context(
570573
logging.INFO,
571574
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()})",
572575
):
576+
# we ensure the file name contain a space
577+
def _file_name_with_space():
578+
file_name = faker.unique.file_name()
579+
return f"{file_name[:1]} {file_name[1:]}"
580+
573581
results = await asyncio.gather(
574582
*(
575583
_upload_file_to_s3(
@@ -578,7 +586,7 @@ async def _create_content(
578586
s3_bucket=storage_s3_bucket,
579587
local_file=local_file,
580588
file_id=TypeAdapter(SimcoreS3FileID).validate_python(
581-
f"{selected_subdir / faker.unique.file_name()}"
589+
f"{selected_subdir / _file_name_with_space()}"
582590
),
583591
)
584592
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)