|
10 | 10 | import filecmp |
11 | 11 | import json |
12 | 12 | import logging |
| 13 | +import random |
13 | 14 | from collections import defaultdict |
14 | 15 | from collections.abc import AsyncIterator, Awaitable, Callable |
15 | 16 | from dataclasses import dataclass |
@@ -669,6 +670,58 @@ async def test_list_objects_pagination( |
669 | 670 | assert len(objects) == (total_num_files - (num_fetch - 1) * limit) |
670 | 671 |
|
671 | 672 |
|
| 673 | +@pytest.mark.parametrize( |
| 674 | + "directory_size, min_file_size, max_file_size, depth", |
| 675 | + [ |
| 676 | + ( |
| 677 | + TypeAdapter(ByteSize).validate_python("1Mib"), |
| 678 | + TypeAdapter(ByteSize).validate_python("1B"), |
| 679 | + TypeAdapter(ByteSize).validate_python("10Kib"), |
| 680 | + 0, |
| 681 | + ) |
| 682 | + ], |
| 683 | + ids=byte_size_ids, |
| 684 | +) |
| 685 | +async def test_list_objects_partial_prefix( |
| 686 | + mocked_s3_server_envs: EnvVarsDict, |
| 687 | + with_s3_bucket: S3BucketName, |
| 688 | + with_uploaded_folder_on_s3: list[UploadedFile], |
| 689 | + simcore_s3_api: SimcoreS3API, |
| 690 | +): |
| 691 | + total_num_files = len(with_uploaded_folder_on_s3) |
| 692 | + # pre-condition |
| 693 | + directories, files = _get_paths_with_prefix( |
| 694 | + with_uploaded_folder_on_s3, prefix_level=0, path_prefix=None |
| 695 | + ) |
| 696 | + assert len(directories) == 1, "test pre-condition not fulfilled!" |
| 697 | + assert not files |
| 698 | + |
| 699 | + first_level_prefix = next(iter(directories)) |
| 700 | + first_level_directories, first_level_files = _get_paths_with_prefix( |
| 701 | + with_uploaded_folder_on_s3, prefix_level=1, path_prefix=first_level_prefix |
| 702 | + ) |
| 703 | + assert ( |
| 704 | + not first_level_directories |
| 705 | + ), "test pre-condition not fulfilled, there should be only files for this test" |
| 706 | + assert len(first_level_files) == total_num_files |
| 707 | + |
| 708 | + a_random_file = random.choice(list(first_level_files)) # noqa: S311 |
| 709 | + a_partial_prefix = a_random_file.name[0:1] |
| 710 | + expected_files = { |
| 711 | + file for file in first_level_files if file.name.startswith(a_partial_prefix) |
| 712 | + } |
| 713 | + |
| 714 | + # now we will fetch the file objects according to the given limit |
| 715 | + objects = await simcore_s3_api.list_objects( |
| 716 | + bucket=with_s3_bucket, |
| 717 | + prefix=first_level_prefix / a_partial_prefix, |
| 718 | + start_after=None, |
| 719 | + is_partial_prefix=True, |
| 720 | + ) |
| 721 | + assert len(objects) == len(expected_files) |
| 722 | + assert {_.as_path() for _ in objects} == expected_files |
| 723 | + |
| 724 | + |
672 | 725 | async def test_get_file_metadata( |
673 | 726 | mocked_s3_server_envs: EnvVarsDict, |
674 | 727 | with_s3_bucket: S3BucketName, |
|
0 commit comments