From 073ae0dd81d53f97e2f45b89b1b2b29442d2455e Mon Sep 17 00:00:00 2001 From: Nilayan Bhattacharya Date: Fri, 27 Oct 2017 13:11:31 -0700 Subject: [PATCH 1/7] Update Docstring (#1) Updated the Docstring and corrected it for next_chunk() --- googleapiclient/http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index f5d08a19a01..7992ea3804f 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -654,7 +654,7 @@ def next_chunk(self, num_retries=0): request only once. Returns: - (status, done): (MediaDownloadStatus, boolean) + (status, done): (MediaDownloadProgress, boolean) The value of 'done' will be True when the media has been fully downloaded. From c0918ce1c56f3bb0ca7d8c6379523ae53ad3ceda Mon Sep 17 00:00:00 2001 From: Nilayan Bhattacharya Date: Mon, 4 Dec 2017 11:26:55 -0800 Subject: [PATCH 2/7] Update Docstring (#1) (#451) (#2) Updated the Docstring and corrected it for next_chunk() From da7de37ce3fdaaf036ef72d9c7a2de110b705e9e Mon Sep 17 00:00:00 2001 From: Nilayan Bhattacharya Date: Mon, 4 Dec 2017 14:02:43 -0800 Subject: [PATCH 3/7] Handling error returned as a list --- googleapiclient/http.py | 7 +++++-- tests/test_http.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index 7992ea3804f..ead308197c9 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -89,7 +89,7 @@ def _should_retry_response(resp_status, content): Args: resp_status: The response status received. - content: The response content body. + content: The response content body. Returns: True if the response should be retried, otherwise False. @@ -112,7 +112,10 @@ def _should_retry_response(resp_status, content): # Content is in JSON format. try: data = json.loads(content.decode('utf-8')) - reason = data['error']['errors'][0]['reason'] + if isinstance(data, dict): + reason = data['error']['errors'][0]['reason'] + else: + reason = data[0]['error']['errors']['reason'] except (UnicodeDecodeError, ValueError, KeyError): LOGGER.warning('Invalid JSON content from response: %s', content) return False diff --git a/tests/test_http.py b/tests/test_http.py index 0df00ab33ba..d4c6d4c8084 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -128,7 +128,7 @@ def request(self, *args, **kwargs): ex = TimeoutError() else: ex = socket.error() - + if self.num_errors == 2: #first try a broken pipe error (#218) ex.errno = socket.errno.EPIPE @@ -739,6 +739,20 @@ def test_media_io_base_download_empty_file(self): } }""" +LIST_NOT_CONFIGURED_RESPONSE = """[ + "error": { + "errors": [ + { + "domain": "usageLimits", + "reason": "accessNotConfigured", + "message": "Access Not Configured" + } + ], + "code": 403, + "message": "Access Not Configured" + } +]""" + class Callbacks(object): def __init__(self): self.responses = {} @@ -956,6 +970,29 @@ def test_no_retry_401_fails_fast(self): request.execute() request._sleep.assert_not_called() + def test_no_retry_403_list_fails(self): + http = HttpMockSequence([ + ({'status': '403'}, LIST_NOT_CONFIGURED_RESPONSE), + ({'status': '200'}, '{}') + ]) + model = JsonModel() + uri = u'https://www.googleapis.com/someapi/v1/collection/?foo=bar' + method = u'POST' + request = HttpRequest( + http, + model.response, + uri, + method=method, + body=u'{}', + headers={'content-type': 'application/json'}) + + request._rand = lambda: 1.0 + request._sleep = mock.MagicMock() + + with self.assertRaises(HttpError): + request.execute() + request._sleep.assert_not_called() + class TestBatch(unittest.TestCase): def setUp(self): From 36c34459d9e7ecfa009b0079ff3e7ae03c2a3ee0 Mon Sep 17 00:00:00 2001 From: Nilayan Bhattacharya Date: Mon, 4 Dec 2017 14:14:26 -0800 Subject: [PATCH 4/7] Update Docstring (#1) (#451) (#3) Updated the Docstring and corrected it for next_chunk() From 1e5b372b729cb3ccf5b5ec0bfaf8a9a1ab281c2a Mon Sep 17 00:00:00 2001 From: Nilayan Bhattacharya Date: Mon, 4 Dec 2017 14:16:29 -0800 Subject: [PATCH 5/7] Spacing stuff --- tests/test_http.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_http.py b/tests/test_http.py index d4c6d4c8084..04e11429a7a 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -128,7 +128,6 @@ def request(self, *args, **kwargs): ex = TimeoutError() else: ex = socket.error() - if self.num_errors == 2: #first try a broken pipe error (#218) ex.errno = socket.errno.EPIPE From ba4ab00b84687b1a043053580b8cd75f56ec225b Mon Sep 17 00:00:00 2001 From: Nilayan Bhattacharya Date: Mon, 4 Dec 2017 17:13:55 -0800 Subject: [PATCH 6/7] Removed random new line to restart travis --- googleapiclient/http.py | 1 - 1 file changed, 1 deletion(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index ead308197c9..eb464490b17 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -513,7 +513,6 @@ class MediaFileUpload(MediaIoBaseUpload): Construct a MediaFileUpload and pass as the media_body parameter of the method. For example, if we had a service that allowed uploading images: - media = MediaFileUpload('cow.png', mimetype='image/png', chunksize=1024*1024, resumable=True) farm.animals().insert( From 1753db5c782b8e41e675b6d135f9214b83ca3d13 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Tue, 5 Dec 2017 14:16:40 -0800 Subject: [PATCH 7/7] Add environment markers to django test dependency (#460) --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 7a3bad221b6..444213ecca3 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,8 @@ deps = mox pyopenssl pycrypto==2.6 - django + django<2.0.0; python_version < '3.0.0' + django>=2.0.0; python_version > '3.0.0' webtest nose coverage>=3.6,<3.99