From 6365773956e984ea4ccdc67919469fe685f9729e Mon Sep 17 00:00:00 2001 From: Kyria Date: Mon, 2 Jul 2018 08:41:00 +0000 Subject: [PATCH] Changed "json_response" to "response" in APIException arguments --- esipy/client.py | 8 ++++---- esipy/exceptions.py | 2 +- esipy/security.py | 6 +++--- test/test_exceptions.py | 29 +---------------------------- 4 files changed, 9 insertions(+), 36 deletions(-) diff --git a/esipy/client.py b/esipy/client.py index bf2dc01..113f48a 100644 --- a/esipy/client.py +++ b/esipy/client.py @@ -144,7 +144,7 @@ def _retry_request(self, req_and_resp, _retry=0, **kwargs): raise APIException( req_and_resp[0].url, res.status, - json_response=res.raw, + response=res.raw, request_param=req_and_resp[0].query, response_header=res.header ) @@ -237,7 +237,7 @@ def _request(self, req_and_resp, **kwargs): raise APIException( request.url, res.status_code, - json_response=res.content, + response=res.content, request_param=request.query, response_header=res.headers ) @@ -252,7 +252,7 @@ def _request(self, req_and_resp, **kwargs): raise APIException( request.url, res.status_code, - json_response=response.raw, + response=response.raw, request_param=request.query, response_header=response.header ) @@ -297,7 +297,7 @@ def head(self, req_and_resp, **kwargs): raise APIException( request.url, res.status_code, - json_response='', + response='', request_param=request.query, response_header=response.header ) diff --git a/esipy/exceptions.py b/esipy/exceptions.py index 75c0e29..bd20eac 100644 --- a/esipy/exceptions.py +++ b/esipy/exceptions.py @@ -8,7 +8,7 @@ class APIException(Exception): def __init__(self, url, code, **kwargs): self.url = url self.status_code = code - self.response = kwargs.pop('json_response', '{}') + self.response = kwargs.pop('response', '{}') self.request_param = kwargs.pop('request_param', {}) self.response_header = kwargs.pop('response_header', {}) super(APIException, self).__init__(str(self)) diff --git a/esipy/security.py b/esipy/security.py index 57bafe2..78f64b8 100644 --- a/esipy/security.py +++ b/esipy/security.py @@ -267,7 +267,7 @@ def refresh(self): raise APIException( request_data['url'], res.status_code, - json_response=res.content, + response=res.content, request_param=request_data, response_header=res.headers ) @@ -287,7 +287,7 @@ def auth(self, code): raise APIException( request_data['url'], res.status_code, - json_response=res.content, + response=res.content, request_param=request_data, response_header=res.headers ) @@ -308,7 +308,7 @@ def verify(self): raise APIException( self.oauth_verify, res.status_code, - json_response=res.content, + response=res.content, request_param=self.__get_oauth_header(), response_header=res.headers ) diff --git a/test/test_exceptions.py b/test/test_exceptions.py index 696d802..d5bd710 100644 --- a/test/test_exceptions.py +++ b/test/test_exceptions.py @@ -18,7 +18,7 @@ def test_api_exception_error(self): e = APIException( TestApiException.URL, TestApiException.STATUS_CODE, - json_response=TestApiException.ERROR_RESPONSE, + response=TestApiException.ERROR_RESPONSE, request_param=TestApiException.PARAMS, response_header=TestApiException.HEADERS ) @@ -28,30 +28,3 @@ def test_api_exception_error(self): self.assertIn(TestApiException.ERROR_RESPONSE['error'], str(e)) self.assertEqual(e.request_param, TestApiException.PARAMS) self.assertEqual(e.response_header, TestApiException.HEADERS) - - def test_api_exception_message(self): - e = APIException( - TestApiException.URL, - TestApiException.STATUS_CODE, - json_response=TestApiException.MESSAGE_RESPONSE - ) - - self.assertEqual(e.url, TestApiException.URL) - self.assertIn(TestApiException.STATUS_CODE_STR, str(e)) - self.assertIn(TestApiException.MESSAGE_RESPONSE['message'], str(e)) - self.assertEqual(e.request_param, {}) - self.assertEqual(e.response_header, {}) - - def test_api_exception_no_message_error(self): - e = APIException( - TestApiException.URL, - TestApiException.STATUS_CODE, - json_response={} - ) - - self.assertEqual(e.url, TestApiException.URL) - self.assertIn(TestApiException.STATUS_CODE_STR, str(e)) - self.assertNotIn(TestApiException.ERROR_RESPONSE['error'], str(e)) - self.assertNotIn(TestApiException.MESSAGE_RESPONSE['message'], str(e)) - self.assertEqual(e.request_param, {}) - self.assertEqual(e.response_header, {})