Skip to content

Commit

Permalink
Merge pull request #24 from kbase/dev-service
Browse files Browse the repository at this point in the history
Add S3ObjectMeta.effective_part_size convenience method
  • Loading branch information
MrCreosote authored Aug 27, 2024
2 parents 926faad + deb7ad5 commit 3246213
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cdmtaskservice/s3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def num_parts(self) -> int:
return 1


@property
def effective_part_size(self):
""" Returns the part size, if present, or the overall object size. """
return self.part_size or self.size


class S3PresignedPost:
"""
A presigned url and fields for posting data to an S3 instance.
Expand Down
24 changes: 21 additions & 3 deletions test/s3/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ async def test_get_object_meta_single_part(minio):
objm = await s3c.get_object_meta(S3Paths(["test-bucket/test_file"]))
assert len(objm) == 1
_check_obj_meta(
objm[0], "test-bucket/test_file", "a925576942e94b2ef57a066101b48876", 10, None, False, 1)
objm[0],
"test-bucket/test_file",
"a925576942e94b2ef57a066101b48876",
10,
None,
False,
1,
10
)


@pytest.mark.asyncio
Expand All @@ -94,6 +102,7 @@ async def test_get_object_meta_multipart(minio):
60000000,
True,
4,
60000000,
)

@pytest.mark.asyncio
Expand All @@ -116,9 +125,17 @@ async def test_get_object_meta_mix(minio):
60000000,
True,
5,
60000000,
)
_check_obj_meta(
objm[1], "nice-bucket/test_file", "a925576942e94b2ef57a066101b48876", 10, None, False, 1)
objm[1],
"nice-bucket/test_file",
"a925576942e94b2ef57a066101b48876",
10,
None,
False,
1,
10)


@pytest.mark.asyncio
Expand Down Expand Up @@ -276,10 +293,11 @@ async def _client(minio):
return await S3Client.create(minio.host, minio.access_key, minio.secret_key)


def _check_obj_meta(objm, path, e_tag, size, part_size, has_parts, num_parts):
def _check_obj_meta(objm, path, e_tag, size, part_size, has_parts, num_parts, effsize):
assert objm.path == path
assert objm.e_tag == e_tag
assert objm.size == size
assert objm.part_size == part_size
assert objm.has_parts is has_parts
assert objm.num_parts == num_parts
assert objm.effective_part_size == effsize

0 comments on commit 3246213

Please sign in to comment.