Skip to content

Commit ccd5e15

Browse files
committed
most tests pass
1 parent 8c0b11d commit ccd5e15

File tree

10 files changed

+54
-45
lines changed

10 files changed

+54
-45
lines changed

google/cloud/storage/_media/_upload.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from google.cloud.storage._media import common
3434
from google.cloud.storage._media import UPLOAD_CHUNK_SIZE
3535
from google.cloud.storage.exceptions import InvalidResponse
36+
from google.cloud.storage.exceptions import DataCorruption
3637

3738
from xml.etree import ElementTree
3839

@@ -752,7 +753,7 @@ def _validate_checksum(self, response):
752753
self._checksum_object.digest()
753754
)
754755
if local_checksum != remote_checksum:
755-
raise common.DataCorruption(
756+
raise DataCorruption(
756757
response,
757758
_UPLOAD_CHECKSUM_MISMATCH_MESSAGE.format(
758759
self._checksum_type.upper(), local_checksum, remote_checksum
@@ -1367,7 +1368,7 @@ def _validate_checksum(self, response):
13671368
self._checksum_object.digest()
13681369
)
13691370
if local_checksum != remote_checksum:
1370-
raise common.DataCorruption(
1371+
raise DataCorruption(
13711372
response,
13721373
_UPLOAD_CHECKSUM_MISMATCH_MESSAGE.format(
13731374
self._checksum_type.upper(), local_checksum, remote_checksum

google/cloud/storage/_media/requests/download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from google.cloud.storage._media import common
2222
from google.cloud.storage._media import _helpers
2323
from google.cloud.storage._media.requests import _request_helpers
24-
24+
from google.cloud.storage.exceptions import DataCorruption
2525

2626
_CHECKSUM_MISMATCH = """\
2727
Checksum mismatch while downloading:
@@ -138,7 +138,7 @@ def _write_to_stream(self, response):
138138
actual_checksum,
139139
checksum_type=self.checksum.upper(),
140140
)
141-
raise common.DataCorruption(response, msg)
141+
raise DataCorruption(response, msg)
142142

143143
def consume(
144144
self,
@@ -327,7 +327,7 @@ def _write_to_stream(self, response):
327327
actual_checksum,
328328
checksum_type=self.checksum.upper(),
329329
)
330-
raise common.DataCorruption(response, msg)
330+
raise DataCorruption(response, msg)
331331

332332
def consume(
333333
self,

google/cloud/storage/_media/requests/upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class ResumableUpload(_request_helpers.RequestsMixin, _upload.ResumableUpload):
332332
checksum Optional([str]): The type of checksum to compute to verify
333333
the integrity of the object. After the upload is complete, the
334334
server-computed checksum of the resulting object will be checked
335-
and google.cloud.storage._media.common.DataCorruption will be raised on
335+
and google.cloud.storage.exceptions.DataCorruption will be raised on
336336
a mismatch. The corrupted file will not be deleted from the remote
337337
host automatically. Supported values are "md5", "crc32c" and None.
338338
The default is None.
@@ -496,7 +496,7 @@ def transmit_next_chunk(
496496
Raises:
497497
~google.cloud.storage.exceptions.InvalidResponse: If the status
498498
code is not 200 or http.client.PERMANENT_REDIRECT.
499-
~google.cloud.storage._media.common.DataCorruption: If this is the final
499+
~google.cloud.storage.exceptions.DataCorruption: If this is the final
500500
chunk, a checksum validation was requested, and the checksum
501501
does not match or is not available.
502502
"""

tests/resumable_media/system/requests/test_download.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from google.cloud.storage._media.requests import _request_helpers
3030
import google.cloud.storage._media.requests.download as download_mod
3131
from googel.cloud.storage.exceptions import InvalidResponse
32+
from googel.cloud.storage.exceptions import DataCorruption
3233
from tests.system import utils
3334

3435

@@ -446,7 +447,7 @@ def test_corrupt_download(self, add_files, corrupting_transport, checksum):
446447
stream = io.BytesIO()
447448
download = self._make_one(media_url, stream=stream, checksum=checksum)
448449
# Consume the resource.
449-
with pytest.raises(common.DataCorruption) as exc_info:
450+
with pytest.raises(DataCorruption) as exc_info:
450451
download.consume(corrupting_transport)
451452

452453
assert download.finished

tests/resumable_media/system/requests/test_upload.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from tests.system import utils
3030
from google.cloud.storage._media import _upload
3131
from google.cloud.storage.exceptions import InvalidResponse
32+
from google.cloud.storage.exceptions import DataCorruption
3233

3334

3435
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -381,7 +382,7 @@ def test_resumable_upload_with_bad_checksum(
381382
with mock.patch.object(
382383
_helpers, "prepare_checksum_digest", return_value=fake_prepared_checksum_digest
383384
):
384-
with pytest.raises(common.DataCorruption) as exc_info:
385+
with pytest.raises(DataCorruption) as exc_info:
385386
_resumable_upload_helper(
386387
authorized_transport, img_stream, cleanup, checksum=checksum
387388
)
@@ -736,7 +737,7 @@ def test_XMLMPU_with_bad_checksum(authorized_transport, bucket, checksum):
736737
"prepare_checksum_digest",
737738
return_value=fake_prepared_checksum_digest,
738739
):
739-
with pytest.raises(common.DataCorruption):
740+
with pytest.raises(DataCorruption):
740741
part.upload(authorized_transport)
741742
finally:
742743
utils.retry_transient_errors(authorized_transport.delete)(

tests/resumable_media/unit/requests/test__helpers.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from google.cloud.storage._media import common
2424
from google.cloud.storage._media.requests import _request_helpers
25+
from google.cloud.storage.exceptions import InvalidResponse
2526

2627
EXPECTED_TIMEOUT = (61, 60)
2728

@@ -104,7 +105,7 @@ def raise_response():
104105
retry_strategy = common.RetryStrategy()
105106
try:
106107
_request_helpers.wait_and_retry(func, _get_status_code, retry_strategy)
107-
except common.InvalidResponse as e:
108+
except InvalidResponse as e:
108109
ret_val = e.response
109110

110111
assert ret_val.status_code == status_codes[-1]
@@ -135,14 +136,14 @@ def test_success_with_retry_custom_delay(self, randint_mock, sleep_mock):
135136
responses = [_make_response(status_code) for status_code in status_codes]
136137

137138
def raise_response():
138-
raise common.InvalidResponse(responses.pop(0))
139+
raise InvalidResponse(responses.pop(0))
139140

140141
func = mock.Mock(side_effect=raise_response)
141142

142143
retry_strategy = common.RetryStrategy(initial_delay=3.0, multiplier=4)
143144
try:
144145
_request_helpers.wait_and_retry(func, _get_status_code, retry_strategy)
145-
except common.InvalidResponse as e:
146+
except InvalidResponse as e:
146147
ret_val = e.response
147148

148149
assert ret_val.status_code == status_codes[-1]
@@ -269,23 +270,23 @@ def test_retry_exceeds_max_cumulative(self, randint_mock, sleep_mock):
269270
status_codes = (
270271
http.client.SERVICE_UNAVAILABLE,
271272
http.client.GATEWAY_TIMEOUT,
272-
common.TOO_MANY_REQUESTS,
273+
http.client.TOO_MANY_REQUESTS,
273274
http.client.INTERNAL_SERVER_ERROR,
274275
http.client.SERVICE_UNAVAILABLE,
275276
http.client.BAD_GATEWAY,
276-
common.TOO_MANY_REQUESTS,
277+
http.client.TOO_MANY_REQUESTS,
277278
)
278279
responses = [_make_response(status_code) for status_code in status_codes]
279280

280281
def raise_response():
281-
raise common.InvalidResponse(responses.pop(0))
282+
raise InvalidResponse(responses.pop(0))
282283

283284
func = mock.Mock(side_effect=raise_response)
284285

285286
retry_strategy = common.RetryStrategy(max_cumulative_retry=100.0)
286287
try:
287288
_request_helpers.wait_and_retry(func, _get_status_code, retry_strategy)
288-
except common.InvalidResponse as e:
289+
except InvalidResponse as e:
289290
ret_val = e.response
290291

291292
assert ret_val.status_code == status_codes[-1]
@@ -313,23 +314,23 @@ def test_retry_exceeds_max_retries(self, randint_mock, sleep_mock):
313314
status_codes = (
314315
http.client.SERVICE_UNAVAILABLE,
315316
http.client.GATEWAY_TIMEOUT,
316-
common.TOO_MANY_REQUESTS,
317+
http.client.TOO_MANY_REQUESTS,
317318
http.client.INTERNAL_SERVER_ERROR,
318319
http.client.SERVICE_UNAVAILABLE,
319320
http.client.BAD_GATEWAY,
320-
common.TOO_MANY_REQUESTS,
321+
http.client.TOO_MANY_REQUESTS,
321322
)
322323
responses = [_make_response(status_code) for status_code in status_codes]
323324

324325
def raise_response():
325-
raise common.InvalidResponse(responses.pop(0))
326+
raise InvalidResponse(responses.pop(0))
326327

327328
func = mock.Mock(side_effect=raise_response)
328329

329330
retry_strategy = common.RetryStrategy(max_retries=6)
330331
try:
331332
_request_helpers.wait_and_retry(func, _get_status_code, retry_strategy)
332-
except common.InvalidResponse as e:
333+
except InvalidResponse as e:
333334
ret_val = e.response
334335

335336
assert ret_val.status_code == status_codes[-1]
@@ -357,19 +358,19 @@ def test_retry_zero_max_retries(self, randint_mock, sleep_mock):
357358
status_codes = (
358359
http.client.SERVICE_UNAVAILABLE,
359360
http.client.GATEWAY_TIMEOUT,
360-
common.TOO_MANY_REQUESTS,
361+
http.client.TOO_MANY_REQUESTS,
361362
)
362363
responses = [_make_response(status_code) for status_code in status_codes]
363364

364365
def raise_response():
365-
raise common.InvalidResponse(responses.pop(0))
366+
raise InvalidResponse(responses.pop(0))
366367

367368
func = mock.Mock(side_effect=raise_response)
368369

369370
retry_strategy = common.RetryStrategy(max_retries=0)
370371
try:
371372
_request_helpers.wait_and_retry(func, _get_status_code, retry_strategy)
372-
except common.InvalidResponse as e:
373+
except InvalidResponse as e:
373374
ret_val = e.response
374375

375376
assert func.call_count == 1

tests/resumable_media/unit/requests/test_download.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from google.cloud.storage._media import _helpers
2323
from google.cloud.storage._media.requests import download as download_mod
2424
from google.cloud.storage._media.requests import _request_helpers
25+
from google.cloud.storage.exceptions import DataCorruption
2526

2627

2728
URL_PREFIX = "https://www.googleapis.com/download/storage/v1/b/{BUCKET}/o/"
@@ -90,7 +91,7 @@ def test__write_to_stream_with_hash_check_fail(self, checksum):
9091
headers = {_helpers._HASH_HEADER: header_value}
9192
response = _mock_response(chunks=[chunk1, chunk2, chunk3], headers=headers)
9293

93-
with pytest.raises(common.DataCorruption) as exc_info:
94+
with pytest.raises(DataCorruption) as exc_info:
9495
download._write_to_stream(response)
9596

9697
assert not download.finished
@@ -268,7 +269,7 @@ def test_consume_with_stream_hash_check_fail(self, checksum):
268269
transport.request.return_value = _mock_response(chunks=chunks, headers=headers)
269270

270271
assert not download.finished
271-
with pytest.raises(common.DataCorruption) as exc_info:
272+
with pytest.raises(DataCorruption) as exc_info:
272273
download.consume(transport)
273274

274275
assert stream.getvalue() == b"".join(chunks)
@@ -529,7 +530,7 @@ def test__write_to_stream_with_hash_check_fail(self, checksum):
529530
headers = {_helpers._HASH_HEADER: header_value}
530531
response = _mock_raw_response(chunks=[chunk1, chunk2, chunk3], headers=headers)
531532

532-
with pytest.raises(common.DataCorruption) as exc_info:
533+
with pytest.raises(DataCorruption) as exc_info:
533534
download._write_to_stream(response)
534535

535536
assert not download.finished
@@ -682,7 +683,7 @@ def test_consume_with_stream_hash_check_fail(self, checksum):
682683
)
683684

684685
assert not download.finished
685-
with pytest.raises(common.DataCorruption) as exc_info:
686+
with pytest.raises(DataCorruption) as exc_info:
686687
download.consume(transport)
687688

688689
assert stream.getvalue() == b"".join(chunks)

tests/resumable_media/unit/test__helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from google.cloud.storage._media import _helpers
2424
from google.cloud.storage._media import common
25+
from google.cloud.storage.exceptions import InvalidResponse
2526

2627

2728
def test_do_nothing():
@@ -49,7 +50,7 @@ def test_success_with_callback(self):
4950
def _failure_helper(self, **kwargs):
5051
response = mock.Mock(headers={}, spec=["headers"])
5152
name = "any-name"
52-
with pytest.raises(common.InvalidResponse) as exc_info:
53+
with pytest.raises(InvalidResponse) as exc_info:
5354
_helpers.header_required(response, name, _get_headers, **kwargs)
5455

5556
error = exc_info.value
@@ -99,7 +100,7 @@ def test_success_with_callback(self):
99100
def test_failure(self):
100101
status_codes = (http.client.CREATED, http.client.NO_CONTENT)
101102
response = _make_response(http.client.OK)
102-
with pytest.raises(common.InvalidResponse) as exc_info:
103+
with pytest.raises(InvalidResponse) as exc_info:
103104
_helpers.require_status_code(response, status_codes, self._get_status_code)
104105

105106
error = exc_info.value
@@ -112,7 +113,7 @@ def test_failure_with_callback(self):
112113
status_codes = (http.client.OK,)
113114
response = _make_response(http.client.NOT_FOUND)
114115
callback = mock.Mock(spec=[])
115-
with pytest.raises(common.InvalidResponse) as exc_info:
116+
with pytest.raises(InvalidResponse) as exc_info:
116117
_helpers.require_status_code(
117118
response, status_codes, self._get_status_code, callback=callback
118119
)
@@ -131,7 +132,7 @@ def test_retryable_failure_without_callback(self):
131132
]
132133
callback = mock.Mock(spec=[])
133134
for retryable_response in retryable_responses:
134-
with pytest.raises(common.InvalidResponse) as exc_info:
135+
with pytest.raises(InvalidResponse) as exc_info:
135136
_helpers.require_status_code(
136137
retryable_response,
137138
status_codes,
@@ -396,7 +397,7 @@ def test_md5_multiple_matches(self):
396397
header_value = "md5={},md5={}".format(self.MD5_CHECKSUM, another_checksum)
397398
response = mock.sentinel.response
398399

399-
with pytest.raises(common.InvalidResponse) as exc_info:
400+
with pytest.raises(InvalidResponse) as exc_info:
400401
_helpers._parse_checksum_header(
401402
header_value, response, checksum_label="md5"
402403
)

0 commit comments

Comments
 (0)