Skip to content

Commit

Permalink
Merge pull request #6 from ardeois/exception_message
Browse files Browse the repository at this point in the history
`UbersmithException` returns the original `code` and `message` given by  the API
  • Loading branch information
mbelang committed Mar 23, 2016
2 parents 67abd3e + 8517a84 commit d764652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ def test_api_raises_exception_with_if_data_status_is_false(self, request_mock):
ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password)

self.expect_a_ubersmith_call(request_mock, method="client.miss", data=data)
assert_that(calling(ubersmith_api.client.miss), raises(ubersmith_client.exceptions.UbersmithException))

with self.assertRaises(ubersmith_client.exceptions.UbersmithException) as cm:
ubersmith_api.client.miss()

catched_exception = cm.exception
assert_that(catched_exception.code, equal_to(1))
assert_that(catched_exception.message, equal_to('invalid method specified: client.miss'))

@requests_mock.mock()
def test_api_raises_exception_for_invalid_status_code(self, request_mock):
Expand Down
4 changes: 2 additions & 2 deletions ubersmith_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def process_request(self, http_method, **kwargs):
response_json = response.json()
if not response_json['status']:
raise UbersmithException(
500,
"error {0}, {1}".format(response_json['error_code'], response_json['error_message'])
response_json['error_code'],
response_json['error_message']
)

return response.json()["data"]
Expand Down

0 comments on commit d764652

Please sign in to comment.