Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: no longer enforce 'destination.content_type' in 'Blob.compose'. #6031

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
20 changes: 20 additions & 0 deletions storage/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
26 changes: 23 additions & 3 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down