def test_invalid_data_displays_invalid_field_data(self): req_obj = KazooRequest("/somepath", auth_required=False) with mock.patch('requests.get') as mock_get: mock_response = mock.Mock() mock_response.status_code = 400 mock_response.json = utils.load_fixture_as_dict( "invalid_data_response.json") mock_get.return_value = mock_response with self.assertRaises(exceptions.KazooApiBadDataError) as cm: req_obj.execute("http://testserver.com") self.assertTrue("realm" in cm.exception.field_errors)
def test_internal_server_error_has_error_message_if_parseable(self): req_obj = KazooRequest("/somepath", auth_required=False) with mock.patch('requests.get') as mock_get: mock_response = mock.Mock() mock_response.status_code = 500 mock_response.headers = {"X-Request-Id": "sdfaskldfjaosdf"} mock_response.json = utils.load_fixture_as_dict( "bad_billing_status_response.json") mock_get.return_value = mock_response with self.assertRaises(exceptions.KazooApiError) as cm: req_obj.execute("http://testserver") ex = cm.exception self.assertTrue("Unable to continue due to billing" in ex.message)
def setUp(self): self.error_response = utils.load_fixture_as_dict( "bad_auth_response.json")