From 90cd5416291c1f2e78c02bf59c5db80a5adf14c2 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 19 Sep 2018 14:32:15 -0400 Subject: [PATCH] No longer enforce 'destination.content_type' not None in 'Blob.compose'. Closes #5834. --- storage/google/cloud/storage/blob.py | 6 ------ storage/tests/system.py | 20 ++++++++++++++++++++ storage/tests/unit/test_blob.py | 26 +++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index 22a833eaceee..aec30e3d8987 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -1374,13 +1374,7 @@ def compose(self, sources, client=None): ``NoneType`` :param client: Optional. The client to use. If not passed, falls back to the ``client`` stored on the blob's bucket. - - :raises: :exc:`ValueError` if this blob does not have its - :attr:`content_type` set. """ - if self.content_type is None: - raise ValueError("Destination 'content_type' not set.") - client = self._require_client(client) query_params = {} diff --git a/storage/tests/system.py b/storage/tests/system.py index de53dd43f865..9a39139d4d1b 100644 --- a/storage/tests/system.py +++ b/storage/tests/system.py @@ -779,6 +779,26 @@ def test_compose_create_new_blob(self): composed = destination.download_as_string() self.assertEqual(composed, SOURCE_1 + SOURCE_2) + def test_compose_create_new_blob_wo_content_type(self): + SOURCE_1 = b'AAA\n' + source_1 = self.bucket.blob('source-1') + source_1.upload_from_string(SOURCE_1) + self.case_blobs_to_delete.append(source_1) + + SOURCE_2 = b'BBB\n' + source_2 = self.bucket.blob('source-2') + source_2.upload_from_string(SOURCE_2) + self.case_blobs_to_delete.append(source_2) + + destination = self.bucket.blob('destination') + + destination.compose([source_1, source_2]) + self.case_blobs_to_delete.append(destination) + + self.assertIsNone(destination.content_type) + composed = destination.download_as_string() + self.assertEqual(composed, SOURCE_1 + SOURCE_2) + def test_compose_replace_existing_blob(self): BEFORE = b'AAA\n' original = self.bucket.blob('original') diff --git a/storage/tests/unit/test_blob.py b/storage/tests/unit/test_blob.py index 4d4da5631421..84f17c56f3c4 100644 --- a/storage/tests/unit/test_blob.py +++ b/storage/tests/unit/test_blob.py @@ -2113,15 +2113,35 @@ def test_compose_wo_content_type_set(self): SOURCE_1 = 'source-1' SOURCE_2 = 'source-2' DESTINATION = 'destinaton' - connection = _Connection() + RESOURCE = {} + after = ({'status': http_client.OK}, RESOURCE) + connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) source_1 = self._make_one(SOURCE_1, bucket=bucket) source_2 = self._make_one(SOURCE_2, bucket=bucket) destination = self._make_one(DESTINATION, bucket=bucket) + # no destination.content_type set - with self.assertRaises(ValueError): - destination.compose(sources=[source_1, source_2]) + destination.compose(sources=[source_1, source_2]) + + self.assertIsNone(destination.content_type) + + kw = connection._requested + self.assertEqual(len(kw), 1) + self.assertEqual(kw[0], { + 'method': 'POST', + 'path': '/b/name/o/%s/compose' % DESTINATION, + 'query_params': {}, + 'data': { + 'sourceObjects': [ + {'name': source_1.name}, + {'name': source_2.name}, + ], + 'destination': {}, + }, + '_target_object': destination, + }) def test_compose_minimal_w_user_project(self): SOURCE_1 = 'source-1'