Skip to content
Merged
Changes from all commits
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
55 changes: 44 additions & 11 deletions storage/tests/unit/test_blob.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -804,7 +804,9 @@ def _check_session_mocks(self, client, transport, expected_url, headers=None):
# second request.
headers["range"] = "bytes=3-5"
headers["accept-encoding"] = "gzip"
call = mock.call("GET", expected_url, data=None, headers=headers)
call = mock.call(
"GET", expected_url, data=None, headers=headers, timeout=mock.ANY
)
self.assertEqual(transport.request.mock_calls, [call, call])

def test__do_download_simple(self):
Expand DownExpand Up@@ -832,7 +834,12 @@ def test__do_download_simple(self):
self.assertEqual(file_obj.getvalue(), b"abcdef")

transport.request.assert_called_once_with(
"GET", download_url, data=None, headers=headers, stream=True
"GET",
download_url,
data=None,
headers=headers,
stream=True,
timeout=mock.ANY,
)

def test__do_download_simple_with_range(self):
Expand DownExpand Up@@ -861,7 +868,12 @@ def test__do_download_simple_with_range(self):
self.assertEqual(headers["range"], "bytes=1-3")

transport.request.assert_called_once_with(
"GET", download_url, data=None, headers=headers, stream=True
"GET",
download_url,
data=None,
headers=headers,
stream=True,
timeout=mock.ANY,
)

def test__do_download_chunked(self):
Expand All@@ -887,7 +899,9 @@ def test__do_download_chunked(self):
self.assertEqual(transport.request.call_count, 2)
# ``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)
call = mock.call(
"GET", download_url, data=None, headers=headers, timeout=mock.ANY
)
self.assertEqual(transport.request.mock_calls, [call, call])

def test__do_download_chunked_with_range(self):
Expand All@@ -913,7 +927,9 @@ def test__do_download_chunked_with_range(self):
self.assertEqual(transport.request.call_count, 2)
# ``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)
call = mock.call(
"GET", download_url, data=None, headers=headers, timeout=mock.ANY
)
self.assertEqual(transport.request.mock_calls, [call, call])

def test_download_to_file_with_failure(self):
Expand DownExpand Up@@ -947,6 +963,7 @@ def test_download_to_file_with_failure(self):
data=None,
headers={"accept-encoding": "gzip"},
stream=True,
timeout=mock.ANY,
)

def test_download_to_file_wo_media_link(self):
Expand DownExpand Up@@ -1008,6 +1025,7 @@ def _download_to_file_helper(self, use_chunks=False):
data=None,
headers={"accept-encoding": "gzip"},
stream=True,
timeout=mock.ANY,
)

def test_download_to_file_default(self):
Expand DownExpand Up@@ -1128,6 +1146,7 @@ def test_download_to_filename_corrupted(self):
data=None,
headers={"accept-encoding": "gzip"},
stream=True,
timeout=mock.ANY,
)

def test_download_to_filename_w_key(self):
Expand DownExpand Up@@ -1346,7 +1365,7 @@ def _do_multipart_success(
)
headers = {"content-type": b'multipart/related; boundary="==0=="'}
transport.request.assert_called_once_with(
"POST", upload_url, data=payload, headers=headers
"POST", upload_url, data=payload, headers=headers, timeout=mock.ANY
)

@mock.patch(u"google.resumable_media._upload.get_boundary", return_value=b"==0==")
Expand DownExpand Up@@ -1505,7 +1524,7 @@ def _initiate_resumable_helper(
if extra_headers is not None:
expected_headers.update(extra_headers)
transport.request.assert_called_once_with(
"POST", upload_url, data=payload, headers=expected_headers
"POST", upload_url, data=payload, headers=expected_headers, timeout=mock.ANY
)

def test__initiate_resumable_upload_no_size(self):
Expand DownExpand Up@@ -1579,7 +1598,9 @@ def _do_resumable_upload_call0(blob, content_type, size=None, predefined_acl=Non
if size is not None:
expected_headers["x-upload-content-length"] = str(size)
payload = json.dumps({"name": blob.name}).encode("utf-8")
return mock.call("POST", upload_url, data=payload, headers=expected_headers)
return mock.call(
"POST", upload_url, data=payload, headers=expected_headers, timeout=mock.ANY
)

@staticmethod
def _do_resumable_upload_call1(
Expand All@@ -1596,7 +1617,13 @@ def _do_resumable_upload_call1(
"content-range": content_range,
}
payload = data[: blob.chunk_size]
return mock.call("PUT", resumable_url, data=payload, headers=expected_headers)
return mock.call(
"PUT",
resumable_url,
data=payload,
headers=expected_headers,
timeout=mock.ANY,
)

@staticmethod
def _do_resumable_upload_call2(
Expand All@@ -1611,7 +1638,13 @@ def _do_resumable_upload_call2(
"content-range": content_range,
}
payload = data[blob.chunk_size :]
return mock.call("PUT", resumable_url, data=payload, headers=expected_headers)
return mock.call(
"PUT",
resumable_url,
data=payload,
headers=expected_headers,
timeout=mock.ANY,
)

def _do_resumable_helper(
self, use_size=False, num_retries=None, predefined_acl=None
Expand DownExpand Up@@ -1924,7 +1957,7 @@ def _create_resumable_upload_session_helper(self, origin=None, side_effect=None)
if origin is not None:
expected_headers["Origin"] = origin
transport.request.assert_called_once_with(
"POST", upload_url, data=payload, headers=expected_headers
"POST", upload_url, data=payload, headers=expected_headers, timeout=mock.ANY
)

def test_create_resumable_upload_session(self):
Expand Down