Unit tests for APIError

This commit is contained in:
Lucidiot 2019-01-30 20:16:54 +01:00
parent 736ec62d3b
commit 1e49fd05b5
No known key found for this signature in database
GPG Key ID: AE3F7205692FA205
2 changed files with 36 additions and 1 deletions

View File

@ -13,7 +13,7 @@ class APIError(Exception):
self.code = error.get('code')
def __repr__(self):
return "<APIError '{}'>".format(str(self))
return "<APIError {}>".format(repr(str(self)))
def __str__(self):
return self.message or 'Unknown error'

View File

@ -0,0 +1,35 @@
from unittest import TestCase
from urbantz.exceptions import APIError
class TestExceptions(TestCase):
@classmethod
def setUpClass(self):
self.error = APIError({
'code': 9000,
'message': "I'm afraid I can't do that, Dave."
})
def test_init(self):
self.assertEqual(self.error.code, 9000)
self.assertEqual(
self.error.message,
"I'm afraid I can't do that, Dave.",
)
def test_empty(self):
error = APIError({})
self.assertIsNone(error.message)
self.assertIsNone(error.code)
self.assertEqual(str(error), 'Unknown error')
self.assertEqual(repr(error), "<APIError 'Unknown error'>")
def test_repr(self):
self.assertEqual(
repr(self.error),
'<APIError "I\'m afraid I can\'t do that, Dave.">',
)
def test_str(self):
self.assertEqual(str(self.error), "I'm afraid I can't do that, Dave.")