From 949dba871776323a6d964c7f30561c55abb22de1 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Mon, 21 Nov 2016 10:22:27 -0800 Subject: [PATCH 1/6] Fix error in resumable upload handler --- googleapiclient/http.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index 14580f0c2b5..0ef10b955e6 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -996,7 +996,11 @@ def _process_response(self, resp, content): elif resp.status == 308: self._in_error_state = False # A "308 Resume Incomplete" indicates we are not done. - self.resumable_progress = int(resp['range'].split('-')[1]) + 1 + try: + self.resumable_progress = int(resp['range'].split('-')[1]) + 1 + except KeyError: + # If resp doesn't contain range header, resumable progress is 0 + self.resumable_progress = 0 if 'location' in resp: self.resumable_uri = resp['location'] else: From a2a50112ee0797b120f728d5b8da9c68d6662174 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 30 Nov 2016 11:26:16 -0800 Subject: [PATCH 2/6] update test case for previously unhanded 308 response --- tests/test_discovery.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 210717d26ca..ec5f77a38dd 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -873,6 +873,8 @@ def test_resumable_multipart_media_good_upload(self): ({'status': '308', 'location': 'http://upload.example.com/3', 'range': '0-%d' % (media_upload.size() - 2)}, ''), + ({'status': '308', + 'location': 'http://upload.example.com/4'}, ''), ({'status': '200'}, '{"foo": "bar"}'), ]) From 35749460a9830f4711a703b2de318f8690ec61d8 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 30 Nov 2016 12:57:05 -0800 Subject: [PATCH 3/6] fix test case for previously unhanded 308 response --- tests/test_discovery.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index ec5f77a38dd..79e11c54b75 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -868,13 +868,13 @@ def test_resumable_multipart_media_good_upload(self): ({'status': '200', 'location': 'http://upload.example.com'}, ''), ({'status': '308', - 'location': 'http://upload.example.com/2', - 'range': '0-12'}, ''), + 'location': 'http://upload.example.com/2', ''}), ({'status': '308', 'location': 'http://upload.example.com/3', - 'range': '0-%d' % (media_upload.size() - 2)}, ''), + 'range': '0-12'}, ''), ({'status': '308', - 'location': 'http://upload.example.com/4'}, ''), + 'location': 'http://upload.example.com/4', + 'range': '0-%d' % (media_upload.size() - 2)}, ''), ({'status': '200'}, '{"foo": "bar"}'), ]) @@ -886,12 +886,17 @@ def test_resumable_multipart_media_good_upload(self): # Two requests should have been made and the resumable_uri should have been # updated for each one. self.assertEquals(request.resumable_uri, 'http://upload.example.com/2') - + self.assertEquals(media_upload, request.resumable) + self.assertEquals(1, request.resumable_progress) + + # This next chuck call should ask for the first chuck size + status, body = request.next_chunk(http=http) + self.assertEquals(request.resumable_uri, 'http://upload.example.com/3') self.assertEquals(media_upload, request.resumable) self.assertEquals(13, request.resumable_progress) status, body = request.next_chunk(http=http) - self.assertEquals(request.resumable_uri, 'http://upload.example.com/3') + self.assertEquals(request.resumable_uri, 'http://upload.example.com/4') self.assertEquals(media_upload.size()-1, request.resumable_progress) self.assertEquals('{"data": {}}', request.body) From 7624724f7fe050e69e9a70f58bf5dd032a78baa2 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 30 Nov 2016 13:04:51 -0800 Subject: [PATCH 4/6] fix test case for previously unhanded 308 response --- tests/test_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 79e11c54b75..226e1e0da43 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -887,7 +887,7 @@ def test_resumable_multipart_media_good_upload(self): # updated for each one. self.assertEquals(request.resumable_uri, 'http://upload.example.com/2') self.assertEquals(media_upload, request.resumable) - self.assertEquals(1, request.resumable_progress) + self.assertEquals(0, request.resumable_progress) # This next chuck call should ask for the first chuck size status, body = request.next_chunk(http=http) From 0933490874b4137a838d73819a5bd7b64685fabb Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 30 Nov 2016 13:09:19 -0800 Subject: [PATCH 5/6] Update test_discovery.py --- tests/test_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 226e1e0da43..c89a2b8303e 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -868,7 +868,7 @@ def test_resumable_multipart_media_good_upload(self): ({'status': '200', 'location': 'http://upload.example.com'}, ''), ({'status': '308', - 'location': 'http://upload.example.com/2', ''}), + 'location': 'http://upload.example.com/2'}, ''), ({'status': '308', 'location': 'http://upload.example.com/3', 'range': '0-12'}, ''), From 15b20b5ce931d9ba308e203cd4ccb79e720d9ad9 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 30 Nov 2016 13:18:37 -0800 Subject: [PATCH 6/6] Update test_discovery.py --- tests/test_discovery.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index c89a2b8303e..7b34606e2f0 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -881,7 +881,7 @@ def test_resumable_multipart_media_good_upload(self): status, body = request.next_chunk(http=http) self.assertEquals(None, body) self.assertTrue(isinstance(status, MediaUploadProgress)) - self.assertEquals(13, status.resumable_progress) + self.assertEquals(0, status.resumable_progress) # Two requests should have been made and the resumable_uri should have been # updated for each one. @@ -889,12 +889,13 @@ def test_resumable_multipart_media_good_upload(self): self.assertEquals(media_upload, request.resumable) self.assertEquals(0, request.resumable_progress) - # This next chuck call should ask for the first chuck size + # This next chuck call should upload the first chunk status, body = request.next_chunk(http=http) self.assertEquals(request.resumable_uri, 'http://upload.example.com/3') self.assertEquals(media_upload, request.resumable) self.assertEquals(13, request.resumable_progress) + # This call will upload the next chunk status, body = request.next_chunk(http=http) self.assertEquals(request.resumable_uri, 'http://upload.example.com/4') self.assertEquals(media_upload.size()-1, request.resumable_progress)