Skip to content

Commit d278abb

Browse files
authored
Require 200 response for initial resumable upload request. (#95)
Closes #63.
1 parent 1f26428 commit d278abb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

google/resumable_media/_upload.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ def _process_initiate_response(self, response):
446446
447447
.. _sans-I/O: https://sans-io.readthedocs.io/
448448
"""
449+
_helpers.require_status_code(
450+
response,
451+
(http_client.OK,),
452+
self._get_status_code,
453+
callback=self._make_invalid,
454+
)
449455
self._resumable_url = _helpers.header_required(
450456
response, u'location', self._get_headers)
451457

tests/unit/test__upload.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,25 +423,26 @@ def test__prepare_initiate_request_bad_stream_position(self):
423423
with pytest.raises(AttributeError):
424424
upload._prepare_initiate_request(None, {}, BASIC_CONTENT)
425425

426-
def test__process_initiate_response_bad_response(self):
426+
def test__process_initiate_response_non_200(self):
427427
upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
428428
_fix_up_virtual(upload)
429429

430-
response = _make_response()
430+
response = _make_response(403)
431431
with pytest.raises(common.InvalidResponse) as exc_info:
432432
upload._process_initiate_response(response)
433433

434434
error = exc_info.value
435435
assert error.response is response
436-
assert len(error.args) == 2
437-
assert error.args[1] == u'location'
436+
assert len(error.args) == 4
437+
assert error.args[1] == 403
438+
assert error.args[3] == 200
438439

439440
def test__process_initiate_response(self):
440441
upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
441442
_fix_up_virtual(upload)
442443

443444
headers = {u'location': u'http://test.invalid?upload_id=kmfeij3234'}
444-
response = mock.Mock(headers=headers, spec=[u'headers'])
445+
response = _make_response(headers=headers)
445446
# Check resumable_url before.
446447
assert upload._resumable_url is None
447448
# Process the actual headers.

0 commit comments

Comments
 (0)