Skip to content

Commit

Permalink
tests: cover 'Blob.download_as_string' when no hash matches (#284)
Browse files Browse the repository at this point in the history
Co-authored-by: Tres Seaver <tseaver@palladion.com>
  • Loading branch information
HemangChothani and tseaver committed Nov 11, 2020
1 parent d457ce3 commit 142639a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/unit/test_blob.py
Expand Up @@ -1567,6 +1567,25 @@ def test_download_as_string_w_hash_response_header_none(self):
self.assertEqual(blob.md5_hash, md5_hash)
self.assertEqual(blob.crc32c, crc32c)

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

response = self._mock_requests_response(
http_client.OK,
headers={"X-Goog-Hash": "bogus=4gcgLQ==,"},
# { "x": 5 } gzipped
content=b"",
)
blob._extract_headers_from_download(response)

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

def test_download_as_bytes_w_generation_match(self):
GENERATION_NUMBER = 6
MEDIA_LINK = "http://example.com/media/"
Expand Down

0 comments on commit 142639a

Please sign in to comment.