Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require 200 response for initial resumable upload request. #95

Merged
merged 2 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions google/resumable_media/_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ def _process_initiate_response(self, response):

.. _sans-I/O: https://sans-io.readthedocs.io/
"""
_helpers.require_status_code(
response,
(http_client.OK,),
self._get_status_code,
callback=self._make_invalid,
)
self._resumable_url = _helpers.header_required(
response, u'location', self._get_headers)

Expand Down
11 changes: 6 additions & 5 deletions tests/unit/test__upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,25 +423,26 @@ def test__prepare_initiate_request_bad_stream_position(self):
with pytest.raises(AttributeError):
upload._prepare_initiate_request(None, {}, BASIC_CONTENT)

def test__process_initiate_response_bad_response(self):
def test__process_initiate_response_non_200(self):
upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
_fix_up_virtual(upload)

response = _make_response()
response = _make_response(403)
with pytest.raises(common.InvalidResponse) as exc_info:
upload._process_initiate_response(response)

error = exc_info.value
assert error.response is response
assert len(error.args) == 2
assert error.args[1] == u'location'
assert len(error.args) == 4
assert error.args[1] == 403
assert error.args[3] == 200

def test__process_initiate_response(self):
upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
_fix_up_virtual(upload)

headers = {u'location': u'http://test.invalid?upload_id=kmfeij3234'}
response = mock.Mock(headers=headers, spec=[u'headers'])
response = _make_response(headers=headers)
# Check resumable_url before.
assert upload._resumable_url is None
# Process the actual headers.
Expand Down