Skip to content

Commit f42c0f9

Browse files
feat(storage): support delete_source_objects in compose API (Address PR feedback)
- Removed unnecessary fixture usage in system test. - Ensured destination metadata is not empty in unit test by setting content_type. - verified end-to-end functionality in system test. Reference PR: googleapis/google-cloud-java#12873 Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
1 parent 178694c commit f42c0f9

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

packages/google-cloud-storage/tests/system/test_blob.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -853,24 +853,24 @@ def test_blob_compose_new_blob(shared_bucket, blobs_to_delete):
853853
assert destination.download_as_bytes() == payload_1 + payload_2
854854

855855

856-
def test_blob_compose_delete_source_objects(shared_bucket, blobs_to_delete):
856+
def test_blob_compose_delete_source_objects(shared_bucket):
857857
payload_1 = b"AAA\n"
858858
source_1 = shared_bucket.blob("source-1-delete")
859859
source_1.upload_from_string(payload_1)
860-
blobs_to_delete.append(source_1)
861860

862861
payload_2 = b"BBB\n"
863862
source_2 = shared_bucket.blob("source-2-delete")
864863
source_2.upload_from_string(payload_2)
865-
blobs_to_delete.append(source_2)
866864

867865
destination = shared_bucket.blob("destination-delete")
868866
destination.compose([source_1, source_2], delete_source_objects=True)
869-
blobs_to_delete.append(destination)
870867

871-
assert destination.download_as_bytes() == payload_1 + payload_2
872-
assert not source_1.exists()
873-
assert not source_2.exists()
868+
try:
869+
assert destination.download_as_bytes() == payload_1 + payload_2
870+
assert not source_1.exists()
871+
assert not source_2.exists()
872+
finally:
873+
destination.delete()
874874

875875

876876
def test_blob_compose_new_blob_wo_content_type(shared_bucket, blobs_to_delete):

packages/google-cloud-storage/tests/unit/test_blob.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4484,6 +4484,7 @@ def test_compose_w_delete_source_objects(self):
44844484
source_1_name = "source-1"
44854485
source_2_name = "source-2"
44864486
destination_name = "destination"
4487+
content_type = "text/plain"
44874488
delete_source_objects = True
44884489
api_response = {}
44894490
client = mock.Mock(spec=["_post_resource"])
@@ -4492,6 +4493,7 @@ def test_compose_w_delete_source_objects(self):
44924493
source_1 = self._make_one(source_1_name, bucket=bucket)
44934494
source_2 = self._make_one(source_2_name, bucket=bucket)
44944495
destination = self._make_one(destination_name, bucket=bucket)
4496+
destination.content_type = content_type
44954497

44964498
destination.compose(
44974499
sources=[source_1, source_2],
@@ -4504,7 +4506,7 @@ def test_compose_w_delete_source_objects(self):
45044506
{"name": source_1.name, "generation": source_1.generation},
45054507
{"name": source_2.name, "generation": source_2.generation},
45064508
],
4507-
"destination": {},
4509+
"destination": {"contentType": content_type},
45084510
"deleteSourceObjects": delete_source_objects,
45094511
}
45104512
expected_query_params = {}

0 commit comments

Comments
 (0)