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), "") def test_repr(self): self.assertEqual( repr(self.error), '', ) def test_str(self): self.assertEqual(str(self.error), "I'm afraid I can't do that, Dave.") def test_fromJSON(self): self.assertEqual(APIError.fromJSON({ 'code': 9000, 'message': "I'm afraid I can't do that, Dave.", }), self.error) def test_toJSON(self): self.assertDictEqual(self.error.toJSON(), { 'code': 9000, 'message': "I'm afraid I can't do that, Dave.", })