From 4c7b49a28cf27f7593c80a46f24f40a14e2399a7 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Fri, 24 Nov 2017 16:10:15 -0800 Subject: [PATCH] Expect bulk results under responses key --- tests/test_arguments.py | 12 ++++++------ tests/test_offlinequeue.py | 20 ++++++++++---------- tests/utils.py | 2 +- wakatime/api.py | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_arguments.py b/tests/test_arguments.py index f1ac4c6..971703a 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -527,7 +527,7 @@ class ArgumentsTestCase(TestCase): logging.disable(logging.NOTSET) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null, 201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now1 = u(int(time.time())) @@ -590,7 +590,7 @@ class ArgumentsTestCase(TestCase): logging.disable(logging.NOTSET) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null, 201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now1 = u(int(time.time())) @@ -653,7 +653,7 @@ class ArgumentsTestCase(TestCase): logging.disable(logging.NOTSET) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null, 201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with TemporaryDirectory() as tempdir: @@ -717,7 +717,7 @@ class ArgumentsTestCase(TestCase): logging.disable(logging.NOTSET) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null, 201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with TemporaryDirectory() as tempdir: @@ -814,7 +814,7 @@ class ArgumentsTestCase(TestCase): logging.disable(logging.NOTSET) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null, 201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now1 = u(int(time.time())) @@ -880,7 +880,7 @@ class ArgumentsTestCase(TestCase): logging.disable(logging.NOTSET) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null, 201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now1 = u(int(time.time())) diff --git a/tests/test_offlinequeue.py b/tests/test_offlinequeue.py index 16c898f..efad729 100644 --- a/tests/test_offlinequeue.py +++ b/tests/test_offlinequeue.py @@ -84,7 +84,7 @@ class OfflineQueueTestCase(TestCase): execute(args) response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null,201], [null,201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response execute(args) @@ -124,7 +124,7 @@ class OfflineQueueTestCase(TestCase): args = ['--file', entity3, '--config', config, '--time', now3, '--project', project3] response = CustomResponse() - response.response_text = '[[{"id":1},201], [{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null,201], [null,201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response execute(args) @@ -190,7 +190,7 @@ class OfflineQueueTestCase(TestCase): response = CustomResponse() response.response_code = 202 - response.response_text = '[[{"id":1},201], [{"error":"error 2"},500], [{"id":3},201], [{"error":4},500]]' + response.response_text = '{"responses": [[null,201], [null,500], [null,201], [null, 500]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with mock.patch('wakatime.main.sys.stdin') as mock_stdin: @@ -273,7 +273,7 @@ class OfflineQueueTestCase(TestCase): response = CustomResponse() response.response_code = 202 - response.response_text = '[[{"id":1},201], [{"error":"error 2"},500], [{"id":3},201], [{"error":4},500]]' + response.response_text = '{"responses": [[null,201], [null,500], [null,201], [null, 500]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with mock.patch('wakatime.main.sys.stdin') as mock_stdin: @@ -328,7 +328,7 @@ class OfflineQueueTestCase(TestCase): response = CustomResponse() response.response_code = 202 - response.response_text = '[[{"id":1},201], [{"id":3},201]]' + response.response_text = '{"responses": [[null,201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with mock.patch('wakatime.main.sys.stdin') as mock_stdin: @@ -390,7 +390,7 @@ class OfflineQueueTestCase(TestCase): response = CustomResponse() response.second_response_code = 401 response.limit = 2 - response.response_text = '[[{"id":1},201], [{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null,201], [null,201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response retval = execute(args) @@ -436,7 +436,7 @@ class OfflineQueueTestCase(TestCase): response = CustomResponse() response.second_response_code = 500 response.limit = 2 - response.response_text = '[[{"id":1},201], [{"id":1},201], [{"id":1},201]]' + response.response_text = '{"responses": [[null,201], [null,201], [null,201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response retval = execute(args) @@ -751,7 +751,7 @@ class OfflineQueueTestCase(TestCase): mock_db_file.return_value = fh.name response = CustomResponse() - response.response_text = '[[{id":1}]]' + response.response_text = '{"responses": [[{id":1},201]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now = u(int(time.time())) @@ -779,7 +779,7 @@ class OfflineQueueTestCase(TestCase): mock_db_file.return_value = fh.name response = CustomResponse() - response.response_text = '[0]' + response.response_text = '{"responses": [1]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now = u(int(time.time())) @@ -807,7 +807,7 @@ class OfflineQueueTestCase(TestCase): mock_db_file.return_value = fh.name response = CustomResponse() - response.response_text = '[[{"id":1}]]' + response.response_text = '{"responses": [[{"id":1}]]}' self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response now = u(int(time.time())) diff --git a/tests/utils.py b/tests/utils.py index bb46d4f..9332022 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -233,7 +233,7 @@ class DynamicIterable(object): class CustomResponse(Response): response_code = 201 - response_text = '[[{"id":1},201]]' + response_text = '{"responses": [[null,201]]}' limit = 0 second_response_code = 0 second_response_text = None diff --git a/wakatime/api.py b/wakatime/api.py index c78ebce..2728c60 100644 --- a/wakatime/api.py +++ b/wakatime/api.py @@ -210,7 +210,7 @@ def _get_results(response): results = [] if response is not None: try: - results = response.json() + results = response.json()['responses'] except: log.traceback(logging.WARNING) return results