Skip to content

Commit

Permalink
mock_copy_object_side_effect
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Dec 31, 2024
1 parent e4b6e84 commit 5919d17
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions api/python/tests/integration/test_put_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ def mock_put_object_side_effect(cls, Bucket, Key, Body, **kwargs):
"PutObject"
)

@classmethod
def mock_copy_object_side_effect(cls, Bucket, Key, **kwargs):
if kwargs.get("ServerSideEncryption") == "aws:kms":
body = cls.mock_get_object_side_effect(Bucket, Key, "EmptyBody")
return {
"CopyObjectResult": body,
"CopySourceVersionId": "test-version-id",
}
else:
raise ClientError({"Error": {"Code": "AccessDenied", "Message": "Access Denied"}}, "CopyObject")

@classmethod
def mock_list_objects_side_effect(cls, Bucket, Prefix, **kwargs):
contents = [{"Key": f"{Prefix}{i}{SUB_HASH}", "Size": i} for i in range(3)]
Expand Down Expand Up @@ -165,7 +176,7 @@ def test_package_push(self, mock_get_object,
def test_package_entry_fetch(self, mock_head_object, mock_get_object, mock_copy_object, mock_list_objects):
mock_head_object.side_effect = self.mock_get_object_side_effect
mock_get_object.side_effect = self.mock_get_object_side_effect
mock_copy_object.side_effect = self.mock_put_object_side_effect
mock_copy_object.side_effect = self.mock_copy_object_side_effect
mock_list_objects.side_effect = self.mock_list_objects_side_effect
#
# Test fetch entry to S3 directory
Expand All @@ -175,8 +186,7 @@ def test_package_entry_fetch(self, mock_head_object, mock_get_object, mock_copy_
pkg_src = dest_dir("test_package_push")
pkg_dest = dest_dir("test_package_entry_fetch")
uri_src = f"{TEST_URI}/{pkg_src}/{TEST_FILE}"
uri_dir = f"{TEST_URI}/{pkg_dest}/"
uri_dest = f"{TEST_URI}/{pkg_dest}/{TEST_FILE}"
uri_dest = f"{TEST_URI}/{pkg_dest}/"

key_src = PhysicalKey.from_url(uri_src)
hash_obj = {"type": "SHA256", "value": "2"+"e885f8bed32d1bdb889b42f4ea9f62c1c095c501e748573fa30896be06120ab"}
Expand All @@ -189,11 +199,17 @@ def test_package_entry_fetch(self, mock_head_object, mock_get_object, mock_copy_

with self.assertRaises(ClientError, msg=COPY_MSG):
print("\n= Package.fetch.fail")
pkg_entry.fetch(uri_dir)
pkg_entry.fetch(uri_dest)

print("\n= Package.fetch")
new_entry = pkg_entry.fetch(uri_dir, put_options=USE_KMS)
new_entry = pkg_entry.fetch(uri_dest, put_options=USE_KMS)
assert new_entry is not None

args = self.mock_call_args(uri_dest)
args = self.mock_call_args(f"{pkg_dest}/{TEST_FILE}")
args.pop("Body")
args["CopySource"] = {
"Bucket": TEST_BUCKET,
"Key": f"{pkg_src}/{TEST_FILE}",
"VersionId": "test-version-id",
}
mock_copy_object.assert_called_with(**args)

0 comments on commit 5919d17

Please sign in to comment.