@@ -524,10 +524,10 @@ async def test_http_check_bucket_connected(
524524
525525
526526def _get_paths_with_prefix (
527- uploaded_files : list [UploadedFile ], * , prefix_level : int , path_prefix : Path
527+ uploaded_files : list [UploadedFile ], * , prefix_level : int , path_prefix : Path | None
528528) -> tuple [set [Path ], set [Path ]]:
529529 def _filter_by_prefix (uploaded_file : UploadedFile ) -> bool :
530- return Path (uploaded_file .s3_key ).is_relative_to (path_prefix )
530+ return Path (uploaded_file .s3_key ).is_relative_to (path_prefix or "" )
531531
532532 directories = {
533533 Path (file .s3_key ).parents [_ROOT_LEVEL - prefix_level ]
@@ -561,22 +561,25 @@ async def test_list_objects(
561561):
562562 # assert pre-conditions
563563 assert len (with_uploaded_folder_on_s3 ) >= 1 , "wrong initialization of test!"
564- top_level_paths = {
565- Path (file .s3_key ).parents [- 2 ] for file in with_uploaded_folder_on_s3
566- }
564+
565+ # Start testing from the root, will return only 1 object (the top level folder)
566+ top_level_directories , top_level_files = _get_paths_with_prefix (
567+ with_uploaded_folder_on_s3 , prefix_level = 0 , path_prefix = None
568+ )
567569 assert (
568- len (top_level_paths ) == 1
570+ len (top_level_directories ) == 1
569571 ), "wrong initialization of test! we expect only one folder here"
572+ assert not top_level_files
573+ top_level_paths = top_level_directories | top_level_files
570574
571- # Start testing from the root, will return only 1 object (the top level folder)
572575 objects = await simcore_s3_api .list_objects (
573576 bucket = with_s3_bucket , prefix = None , start_after = None
574577 )
575578 assert len (objects ) == len (top_level_paths )
576579 assert {_ .as_path () for _ in objects } == top_level_paths
577580
578581 # go one level deeper, will return all the folders + files in the first level
579- first_level_prefix = next ( iter ( top_level_paths ))
582+ first_level_prefix = random . choice ( list ( top_level_directories )) # noqa: S311
580583 first_level_directories , first_level_files = _get_paths_with_prefix (
581584 with_uploaded_folder_on_s3 , prefix_level = 1 , path_prefix = first_level_prefix
582585 )
@@ -604,8 +607,12 @@ async def test_list_objects(
604607 bucket = with_s3_bucket , prefix = second_level_prefix , start_after = None
605608 )
606609 assert len (objects ) == len (second_level_paths )
607- received_paths = {obj .as_path () for obj in objects }
608- assert second_level_paths == received_paths
610+ assert {_ .as_path () for _ in objects } == second_level_paths
611+ # check files and directories are correctly separated
612+ received_files = {_ for _ in objects if isinstance (_ , S3MetaData )}
613+ received_directories = {_ for _ in objects if isinstance (_ , S3DirectoryMetaData )}
614+ assert len (received_files ) == len (second_level_files )
615+ assert len (received_directories ) == len (second_level_directories )
609616
610617
611618async def test_get_file_metadata (
0 commit comments