Skip to content

Commit

Permalink
fix(blob.py): returns blob hashes (md5, crc32c) when 'X-Goog-Hash hea…
Browse files Browse the repository at this point in the history
…der' is not provided
  • Loading branch information
remmykilonzo committed Sep 2, 2020
1 parent e190f1c commit 8b4ca5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions google/cloud/storage/blob.py
Expand Up @@ -818,8 +818,8 @@ def _extract_headers_from_download(self, response):
method, digest = match.groups()
digests[method] = digest

self.crc32c = digests.get("crc32c", None)
self.md5_hash = digests.get("md5", None)
self.crc32c = digests.get("crc32c", self.crc32c)
self.md5_hash = digests.get("md5", self.md5_hash)

def _do_download(
self,
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/test_blob.py
Expand Up @@ -1524,10 +1524,16 @@ def test_download_as_string_w_response_headers(self):

def test_download_as_string_w_hash_response_header_none(self):
blob_name = "blob-name"
md5_hash = "CS9tHYTtyFntzj7B9nkkJQ=="
crc32c = "4gcgLQ=="
client = mock.Mock(spec=["_http"])
bucket = _Bucket(client)
media_link = "http://example.com/media/"
properties = {"mediaLink": media_link}
properties = {
"mediaLink": media_link,
"md5Hash": md5_hash,
"crc32c": crc32c,
}
blob = self._make_one(blob_name, bucket=bucket, properties=properties)

response = self._mock_requests_response(
Expand All @@ -1538,8 +1544,8 @@ def test_download_as_string_w_hash_response_header_none(self):
)
blob._extract_headers_from_download(response)

self.assertIsNone(blob.md5_hash)
self.assertIsNone(blob.crc32c)
self.assertEqual(blob.md5_hash, md5_hash)
self.assertEqual(blob.crc32c, crc32c)

def test_download_as_bytes_w_generation_match(self):
GENERATION_NUMBER = 6
Expand Down

0 comments on commit 8b4ca5d

Please sign in to comment.