Skip to content

Commit

Permalink
Actually passing through total_bytes in requests.ResumableUpload.init…
Browse files Browse the repository at this point in the history
…iate.

This was a **bug** before now.
  • Loading branch information
dhermes committed May 3, 2017
1 parent 9eac214 commit bcf80d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion google/resumable_media/requests/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ def initiate(self, transport, stream, metadata, content_type,
~requests.Response: The HTTP response returned by ``transport``.
"""
method, url, payload, headers = self._prepare_initiate_request(
stream, metadata, content_type, stream_final=stream_final)
stream, metadata, content_type,
total_bytes=total_bytes, stream_final=stream_final)
result = _helpers.http_request(
transport, method, url, data=payload, headers=headers)
self._process_initiate_response(result)
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/requests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def test_initiate(self):
# Check resumable_url before.
assert upload._resumable_url is None
# Make request and check the return value (against the mock).
response = upload.initiate(transport, stream, metadata, BASIC_CONTENT)
total_bytes = 100
assert total_bytes > len(data)
response = upload.initiate(
transport, stream, metadata, BASIC_CONTENT,
total_bytes=total_bytes, stream_final=False)
assert response is transport.request.return_value
# Check resumable_url after.
assert upload._resumable_url == location
Expand All @@ -114,7 +118,7 @@ def test_initiate(self):
expected_headers = {
u'content-type': JSON_TYPE,
u'x-upload-content-type': BASIC_CONTENT,
u'x-upload-content-length': u'{:d}'.format(len(data)),
u'x-upload-content-length': u'{:d}'.format(total_bytes),
}
transport.request.assert_called_once_with(
u'POST', RESUMABLE_URL, data=json_bytes, headers=expected_headers)
Expand Down

0 comments on commit bcf80d2

Please sign in to comment.