Skip to content

Commit 2ef612e

Browse files
tests: cover 'Blob.download_as_string' when no hash matches (#284)
Co-authored-by: Tres Seaver <tseaver@palladion.com>
1 parent aabaf18 commit 2ef612e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,25 @@ def test_download_as_string_w_hash_response_header_none(self):
15671567
self.assertEqual(blob.md5_hash, md5_hash)
15681568
self.assertEqual(blob.crc32c, crc32c)
15691569

1570+
def test_download_as_string_w_response_headers_not_match(self):
1571+
blob_name = "blob-name"
1572+
client = mock.Mock(spec=["_http"])
1573+
bucket = _Bucket(client)
1574+
media_link = "http://example.com/media/"
1575+
properties = {"mediaLink": media_link}
1576+
blob = self._make_one(blob_name, bucket=bucket, properties=properties)
1577+
1578+
response = self._mock_requests_response(
1579+
http_client.OK,
1580+
headers={"X-Goog-Hash": "bogus=4gcgLQ==,"},
1581+
# { "x": 5 } gzipped
1582+
content=b"",
1583+
)
1584+
blob._extract_headers_from_download(response)
1585+
1586+
self.assertIsNone(blob.md5_hash)
1587+
self.assertIsNone(blob.crc32c)
1588+
15701589
def test_download_as_bytes_w_generation_match(self):
15711590
GENERATION_NUMBER = 6
15721591
MEDIA_LINK = "http://example.com/media/"

0 commit comments

Comments
 (0)