Skip to content

Commit f8ea28a

Browse files
authored
Revert "Fix tests b0rken by 'google-resumable-media 0.4.0' release. (#9204)"
This reverts commit e9f27b3.
1 parent b4ea85c commit f8ea28a

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

storage/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
dependencies = [
3232
"google-auth >= 1.2.0",
3333
"google-cloud-core >= 1.0.3, < 2.0dev",
34-
"google-resumable-media >= 0.4.0",
34+
"google-resumable-media >= 0.3.1",
3535
]
3636
extras = {}
3737

storage/tests/unit/test_blob.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -755,15 +755,13 @@ def test__get_download_url_on_the_fly_with_kms_key_name(self):
755755
@staticmethod
756756
def _mock_requests_response(status_code, headers, content=b"", stream=False):
757757
import requests
758-
from urllib3.response import HTTPResponse
759758

760759
response = requests.Response()
761760
response.status_code = status_code
762761
response.headers.update(headers)
763762
if stream:
764-
raw = mock.create_autospec(HTTPResponse, instance=True)
763+
raw = io.BytesIO(content)
765764
raw.headers = headers
766-
raw.stream.return_value = iter([content])
767765
response.raw = raw
768766
response._content = False
769767
else:
@@ -816,12 +814,7 @@ def _check_session_mocks(self, client, transport, expected_url, headers=None):
816814
headers["range"] = "bytes=3-5"
817815
headers["accept-encoding"] = "gzip"
818816
call = mock.call(
819-
"GET",
820-
expected_url,
821-
data=None,
822-
headers=headers,
823-
stream=True,
824-
timeout=mock.ANY,
817+
"GET", expected_url, data=None, headers=headers, timeout=mock.ANY
825818
)
826819
self.assertEqual(transport.request.mock_calls, [call, call])
827820

@@ -916,12 +909,7 @@ def test__do_download_chunked(self):
916909
# ``headers`` was modified (in place) once for each API call.
917910
self.assertEqual(headers, {"range": "bytes=3-5"})
918911
call = mock.call(
919-
"GET",
920-
download_url,
921-
data=None,
922-
headers=headers,
923-
stream=True,
924-
timeout=mock.ANY,
912+
"GET", download_url, data=None, headers=headers, timeout=mock.ANY
925913
)
926914
self.assertEqual(transport.request.mock_calls, [call, call])
927915

@@ -949,12 +937,7 @@ def test__do_download_chunked_with_range(self):
949937
# ``headers`` was modified (in place) once for each API call.
950938
self.assertEqual(headers, {"range": "bytes=3-4"})
951939
call = mock.call(
952-
"GET",
953-
download_url,
954-
data=None,
955-
headers=headers,
956-
stream=True,
957-
timeout=mock.ANY,
940+
"GET", download_url, data=None, headers=headers, timeout=mock.ANY
958941
)
959942
self.assertEqual(transport.request.mock_calls, [call, call])
960943

@@ -1103,27 +1086,32 @@ def test_download_to_filename_wo_updated(self):
11031086
self._download_to_filename_helper()
11041087

11051088
def test_download_to_filename_corrupted(self):
1106-
from urllib3.response import HTTPResponse
11071089
from google.resumable_media import DataCorruption
11081090
from google.resumable_media.requests.download import _CHECKSUM_MISMATCH
11091091

11101092
blob_name = "blob-name"
11111093
transport = mock.Mock(spec=["request"])
11121094
empty_hash = base64.b64encode(hashlib.md5(b"").digest()).decode(u"utf-8")
11131095
headers = {"x-goog-hash": "md5=" + empty_hash}
1114-
chunks = (b"noms1", b"coooookies2")
1115-
mock_raw = mock.create_autospec(HTTPResponse, instance=True)
1116-
mock_raw.headers = headers
1117-
mock_raw.stream.return_value = iter(chunks)
1096+
mock_raw = mock.Mock(headers=headers, spec=["headers"])
11181097
response = mock.MagicMock(
11191098
headers=headers,
11201099
status_code=http_client.OK,
11211100
raw=mock_raw,
1122-
spec=["__enter__", "__exit__", "headers", "status_code", "raw"],
1101+
spec=[
1102+
"__enter__",
1103+
"__exit__",
1104+
"headers",
1105+
"iter_content",
1106+
"status_code",
1107+
"raw",
1108+
],
11231109
)
11241110
# i.e. context manager returns ``self``.
11251111
response.__enter__.return_value = response
11261112
response.__exit__.return_value = None
1113+
chunks = (b"noms1", b"coooookies2")
1114+
response.iter_content.return_value = iter(chunks)
11271115

11281116
transport.request.return_value = response
11291117
# Create a fake client/bucket and use them in the Blob() constructor.
@@ -1158,7 +1146,9 @@ def test_download_to_filename_corrupted(self):
11581146
# Check the mocks.
11591147
response.__enter__.assert_called_once_with()
11601148
response.__exit__.assert_called_once_with(None, None, None)
1161-
mock_raw.stream.assert_called_once_with(8192, decode_content=False)
1149+
response.iter_content.assert_called_once_with(
1150+
chunk_size=8192, decode_unicode=False
1151+
)
11621152
transport.request.assert_called_once_with(
11631153
"GET",
11641154
media_link,

0 commit comments

Comments
 (0)