def test_delete_with_timeout(self, mock_delete): mock_delete.side_effect = Timeout(self.error_msg) with app.app_context() as ac: ac.g.trace_id = None ac.g.requests = requests.Session() with app.test_request_context(): with self.assertRaises(ApplicationError) as context: AccountAPI.delete(self, '1234-567-890') self.assertTrue(ApplicationError in str(context.exception)) self.assertEqual( context.exception.message, 'Connection to account_api timed out: {}'.format( self.error_msg)) self.assertEqual(context.exception.code, 'E711') self.assertEqual(context.exception.http_code, 500)
def test_delete_connection_error(self, mock_delete): with app.app_context() as ac: ac.g.trace_id = None ac.g.requests = requests.Session() with app.test_request_context(): mock_delete.side_effect = ConnectionError(self.error_msg) with self.assertRaises(ApplicationError) as context: AccountAPI.delete(self, '1234-567-890') self.assertEqual( context.exception.message, 'Encountered an error connecting to account_api: {}'. format(self.error_msg)) self.assertEqual(context.exception.code, 'E710') self.assertEqual(context.exception.http_code, 500)
def test_delete_http_error(self, mock_delete): with app.app_context() as ac: ac.g.trace_id = None ac.g.requests = requests.Session() with app.test_request_context(): mock_delete.side_effect = HTTPError(self.error_msg) with self.assertRaises(ApplicationError) as context: AccountAPI.delete(self, '1234-567-890') self.assertEqual( context.exception.message, 'Received the following response from account_api: {}'. format(self.error_msg)) self.assertEqual(context.exception.code, 'E709') self.assertEqual(context.exception.http_code, 500)
def test_delete(self, mock_delete): with app.app_context() as ac: ac.g.trace_id = None ac.g.requests = requests.Session() with app.test_request_context(): mock_delete.return_value.text = 'Success' mock_delete.return_value.status_code = 200 response = AccountAPI.delete(self, '1234-567-890') assert response == {'message': 'deleted'}