diff --git a/storage/setup.py b/storage/setup.py index 0c80684f6234..f0df696179d3 100644 --- a/storage/setup.py +++ b/storage/setup.py @@ -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, != 0.4.0, < 0.5dev", ] extras = {} diff --git a/storage/tests/unit/test_blob.py b/storage/tests/unit/test_blob.py index c3e94f19ef96..2bef097987dd 100644 --- a/storage/tests/unit/test_blob.py +++ b/storage/tests/unit/test_blob.py @@ -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: @@ -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]) @@ -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]) @@ -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]) @@ -1103,7 +1086,6 @@ 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 @@ -1111,19 +1093,25 @@ def test_download_to_filename_corrupted(self): 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. @@ -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,