Skip to content

Commit

Permalink
Changed "json_response" to "response" in APIException arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyria committed Jul 2, 2018
1 parent bb1d419 commit 6365773
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
8 changes: 4 additions & 4 deletions esipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion esipy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions esipy/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down
29 changes: 1 addition & 28 deletions test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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, {})

0 comments on commit 6365773

Please sign in to comment.