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: Revert "Fix tests b0rken by 'google-resumable-media 0.4.0' release." #9240

Merged
merged 3 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion storage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
dependencies = [
"google-auth >= 1.2.0",
"google-cloud-core >= 1.0.3, < 2.0dev",
"google-resumable-media >= 0.4.0",
"google-resumable-media >= 0.3.1",
]
extras = {}

Expand Down
46 changes: 18 additions & 28 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,15 +755,13 @@ def test__get_download_url_on_the_fly_with_kms_key_name(self):
@staticmethod
def _mock_requests_response(status_code, headers, content=b"", stream=False):
import requests
from urllib3.response import HTTPResponse

response = requests.Response()
response.status_code = status_code
response.headers.update(headers)
if stream:
raw = mock.create_autospec(HTTPResponse, instance=True)
raw = io.BytesIO(content)
raw.headers = headers
raw.stream.return_value = iter([content])
response.raw = raw
response._content = False
else:
Expand Down Expand Up @@ -816,12 +814,7 @@ def _check_session_mocks(self, client, transport, expected_url, headers=None):
headers["range"] = "bytes=3-5"
headers["accept-encoding"] = "gzip"
call = mock.call(
"GET",
expected_url,
data=None,
headers=headers,
stream=True,
timeout=mock.ANY,
"GET", expected_url, data=None, headers=headers, timeout=mock.ANY
)
self.assertEqual(transport.request.mock_calls, [call, call])

Expand Down Expand Up @@ -916,12 +909,7 @@ def test__do_download_chunked(self):
# ``headers`` was modified (in place) once for each API call.
self.assertEqual(headers, {"range": "bytes=3-5"})
call = mock.call(
"GET",
download_url,
data=None,
headers=headers,
stream=True,
timeout=mock.ANY,
"GET", download_url, data=None, headers=headers, timeout=mock.ANY
)
self.assertEqual(transport.request.mock_calls, [call, call])

Expand Down Expand Up @@ -949,12 +937,7 @@ def test__do_download_chunked_with_range(self):
# ``headers`` was modified (in place) once for each API call.
self.assertEqual(headers, {"range": "bytes=3-4"})
call = mock.call(
"GET",
download_url,
data=None,
headers=headers,
stream=True,
timeout=mock.ANY,
"GET", download_url, data=None, headers=headers, timeout=mock.ANY
)
self.assertEqual(transport.request.mock_calls, [call, call])

Expand Down Expand Up @@ -1103,27 +1086,32 @@ def test_download_to_filename_wo_updated(self):
self._download_to_filename_helper()

def test_download_to_filename_corrupted(self):
from urllib3.response import HTTPResponse
from google.resumable_media import DataCorruption
from google.resumable_media.requests.download import _CHECKSUM_MISMATCH

blob_name = "blob-name"
transport = mock.Mock(spec=["request"])
empty_hash = base64.b64encode(hashlib.md5(b"").digest()).decode(u"utf-8")
headers = {"x-goog-hash": "md5=" + empty_hash}
chunks = (b"noms1", b"coooookies2")
mock_raw = mock.create_autospec(HTTPResponse, instance=True)
mock_raw.headers = headers
mock_raw.stream.return_value = iter(chunks)
mock_raw = mock.Mock(headers=headers, spec=["headers"])
response = mock.MagicMock(
headers=headers,
status_code=http_client.OK,
raw=mock_raw,
spec=["__enter__", "__exit__", "headers", "status_code", "raw"],
spec=[
"__enter__",
"__exit__",
"headers",
"iter_content",
"status_code",
"raw",
],
)
# i.e. context manager returns ``self``.
response.__enter__.return_value = response
response.__exit__.return_value = None
chunks = (b"noms1", b"coooookies2")
response.iter_content.return_value = iter(chunks)

transport.request.return_value = response
# Create a fake client/bucket and use them in the Blob() constructor.
Expand Down Expand Up @@ -1158,7 +1146,9 @@ def test_download_to_filename_corrupted(self):
# Check the mocks.
response.__enter__.assert_called_once_with()
response.__exit__.assert_called_once_with(None, None, None)
mock_raw.stream.assert_called_once_with(8192, decode_content=False)
response.iter_content.assert_called_once_with(
chunk_size=8192, decode_unicode=False
)
transport.request.assert_called_once_with(
"GET",
media_link,
Expand Down