class APITest(unittest.TestCase): """ Test case for the API functionality. This unit test does not interact with the API itself, therefore, an acceptance test is needed. """ def setUp(self): self.api = APIConsumer() def test_init(self): """Tests the behaviour of the constructor.""" self.assertEqual(APIConsumer().base_url, 'https://api.ia.utwente.nl/app/lennart/') self.assertEqual(APIConsumer(base_url='https://test.example/api').base_url, 'https://test.example/api/') def test_exceptions(self): """Tests whether the correct exceptions are selected.""" self.assertEqual(self.api._get_exception(None), exceptions.APIError) self.assertEqual(self.api._get_exception(666), exceptions.APIError) self.assertEqual(self.api._get_exception(-32700), exceptions.APIError) self.assertEqual(self.api._get_exception(403), exceptions.NotLoggedInError) self.assertEqual(self.api._get_exception(406), exceptions.UnknownDeviceError) self.assertEqual(self.api._get_exception(412), exceptions.SignupError) self.assertEqual(self.api._get_exception(500), exceptions.OtherError)
def setUp(self): self.api = APIConsumer()