diff --git a/magnum/api/middleware/parsable_error.py b/magnum/api/middleware/parsable_error.py index dd092a4778..bcfc3fac0c 100644 --- a/magnum/api/middleware/parsable_error.py +++ b/magnum/api/middleware/parsable_error.py @@ -57,9 +57,39 @@ class ParsableErrorMiddleware(object): return start_response(status, headers, exc_info) app_iter = self.app(environ, replacement_start_response) + if (state['status_code'] // 100) not in (2, 3): - body = [six.b(json.dumps({'error_message': - six.b('\n').join(app_iter).decode('utf-8')}))] + errs = [] + for err_str in app_iter: + err = {} + try: + err = json.loads(err_str.decode('utf-8')) + except ValueError: + pass + + if 'title' in err and 'description' in err: + title = err['title'] + desc = err['description'] + elif 'faultstring' in err: + title = err['faultstring'].split('.', 1)[0] + desc = err['faultstring'] + else: + title = '' + desc = '' + + code = err['faultcode'].lower() if 'faultcode' in err else '' + + errs.append({ + 'request_id': '', + 'code': code, + 'status': state['status_code'], + 'title': title, + 'detail': desc, + 'links': [] + }) + + body = [six.b(json.dumps({'errors': errs}))] + state['headers'].append(('Content-Type', 'application/json')) state['headers'].append(('Content-Length', str(len(body[0])))) else: diff --git a/magnum/tests/unit/api/controllers/v1/test_bay.py b/magnum/tests/unit/api/controllers/v1/test_bay.py index ce1f070cc1..15967f1b8c 100644 --- a/magnum/tests/unit/api/controllers/v1/test_bay.py +++ b/magnum/tests/unit/api/controllers/v1/test_bay.py @@ -11,7 +11,6 @@ # limitations under the License. import datetime -import json import mock from oslo_config import cfg @@ -88,7 +87,7 @@ class TestListBay(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_get_one_by_name_multiple_bay(self): obj_utils.create_test_bay(self.context, name='test_bay', @@ -98,7 +97,7 @@ class TestListBay(api_base.FunctionalTest): response = self.get_json('/bays/test_bay', expect_errors=True) self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_get_all_with_pagination_marker(self): bay_list = [] @@ -265,7 +264,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('oslo_utils.timeutils.utcnow') def test_replace_ok_by_name_multiple_bay(self, mock_utcnow): @@ -292,7 +291,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_invalid_node_count(self): response = self.patch_json('/bays/%s' % self.bay.uuid, @@ -301,7 +300,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_non_existent_bay(self): response = self.patch_json('/bays/%s' % utils.generate_uuid(), @@ -311,7 +310,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_bay_name_failed(self): response = self.patch_json('/bays/%s' % self.bay.uuid, @@ -321,7 +320,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_add_non_existent_property(self): response = self.patch_json( @@ -330,7 +329,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_ok(self): response = self.get_json('/bays/%s' % self.bay.uuid) @@ -356,7 +355,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_baymodel_id(self): response = self.patch_json('/bays/%s' % self.bay.uuid, @@ -364,7 +363,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_non_existent_property(self): response = self.patch_json( @@ -373,7 +372,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestPost(api_base.FunctionalTest): @@ -469,7 +468,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_with_baymodel_name(self, mock_valid_os_res): @@ -487,7 +486,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_with_node_count_negative(self, mock_valid_os_res): @@ -497,7 +496,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_with_no_node_count(self, mock_valid_os_res): @@ -517,7 +516,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_with_no_master_count(self, mock_valid_os_res): @@ -535,7 +534,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_with_invalid_empty_name(self, mock_valid_os_res): @@ -544,7 +543,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_without_name(self, mock_valid_os_res): @@ -586,7 +585,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch('magnum.api.attr_validator.validate_os_resources') def test_create_bay_with_timeout_zero(self, mock_valid_os_res): @@ -673,14 +672,14 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_bay_not_found(self): uuid = utils.generate_uuid() response = self.delete('/bays/%s' % uuid, expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_bay_with_pods(self): obj_utils.create_test_pod(self.context, bay_uuid=self.bay.uuid) @@ -704,7 +703,7 @@ class TestDelete(api_base.FunctionalTest): response = self.delete('/bays/not_found', expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_bay_with_name(self): response = self.delete('/bays/%s' % self.bay.name, @@ -719,7 +718,7 @@ class TestDelete(api_base.FunctionalTest): response = self.delete('/bays/test_bay', expect_errors=True) self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestBayPolicyEnforcement(api_base.FunctionalTest): @@ -735,7 +734,7 @@ class TestBayPolicyEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_baymodel.py b/magnum/tests/unit/api/controllers/v1/test_baymodel.py index 22e72839e7..672f9fb498 100644 --- a/magnum/tests/unit/api/controllers/v1/test_baymodel.py +++ b/magnum/tests/unit/api/controllers/v1/test_baymodel.py @@ -11,7 +11,6 @@ # limitations under the License. import datetime -import json import mock from oslo_config import cfg @@ -88,7 +87,7 @@ class TestListBayModel(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_get_one_by_name_multiple_baymodel(self): obj_utils.create_test_baymodel( @@ -102,7 +101,7 @@ class TestListBayModel(api_base.FunctionalTest): expect_errors=True) self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_get_all_with_pagination_marker(self): bm_list = [] @@ -216,7 +215,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_update_baymodel_with_bay(self): baymodel = obj_utils.create_test_baymodel(self.context) @@ -229,8 +228,8 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) - self.assertIn(baymodel.uuid, response.json['error_message']) + self.assertTrue(response.json['errors']) + self.assertIn(baymodel.uuid, response.json['errors'][0]['detail']) @mock.patch.object(magnum_policy, 'enforce') def test_update_public_baymodel_success(self, mock_policy): @@ -333,7 +332,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_mandatory_property_fail(self): mandatory_properties = ('/image_id', '/keypair_id', @@ -347,7 +346,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_add_root_non_existent(self): response = self.patch_json( @@ -356,7 +355,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_uuid(self): response = self.patch_json('/baymodels/%s' % self.baymodel.uuid, @@ -364,7 +363,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestPost(api_base.FunctionalTest): @@ -790,7 +789,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_baymodel_with_bay(self): baymodel = obj_utils.create_test_baymodel(self.context) @@ -799,15 +798,15 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) - self.assertIn(baymodel.uuid, response.json['error_message']) + self.assertTrue(response.json['errors']) + self.assertIn(baymodel.uuid, response.json['errors'][0]['detail']) def test_delete_baymodel_not_found(self): uuid = utils.generate_uuid() response = self.delete('/baymodels/%s' % uuid, expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_baymodel_with_name(self): baymodel = obj_utils.create_test_baymodel(self.context) @@ -819,7 +818,7 @@ class TestDelete(api_base.FunctionalTest): response = self.delete('/baymodels/not_found', expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_multiple_baymodel_by_name(self): obj_utils.create_test_baymodel(self.context, name='test_baymodel', @@ -829,7 +828,7 @@ class TestDelete(api_base.FunctionalTest): response = self.delete('/baymodels/test_baymodel', expect_errors=True) self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestBayModelPolicyEnforcement(api_base.FunctionalTest): @@ -841,7 +840,7 @@ class TestBayModelPolicyEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_certificate.py b/magnum/tests/unit/api/controllers/v1/test_certificate.py index fb8d18ea0a..47b280ebf2 100644 --- a/magnum/tests/unit/api/controllers/v1/test_certificate.py +++ b/magnum/tests/unit/api/controllers/v1/test_certificate.py @@ -10,7 +10,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import mock from magnum.api.controllers.v1 import certificate as api_cert @@ -79,7 +78,7 @@ class TestGetCertificate(api_base.FunctionalTest): self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_get_one_by_name_multiple_bay(self): obj_utils.create_test_bay(self.context, name='test_bay', @@ -92,7 +91,7 @@ class TestGetCertificate(api_base.FunctionalTest): self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_links(self): fake_cert = apiutils.cert_post_data() @@ -159,7 +158,7 @@ class TestPost(api_base.FunctionalTest): self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestCertPolicyEnforcement(api_base.FunctionalTest): @@ -174,7 +173,7 @@ class TestCertPolicyEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_one(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_container.py b/magnum/tests/unit/api/controllers/v1/test_container.py index d9f5a1cd94..94ed17beda 100644 --- a/magnum/tests/unit/api/controllers/v1/test_container.py +++ b/magnum/tests/unit/api/controllers/v1/test_container.py @@ -10,7 +10,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import mock from mock import patch from webtest.app import AppError @@ -641,7 +640,7 @@ class TestContainerEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_magnum_service.py b/magnum/tests/unit/api/controllers/v1/test_magnum_service.py index 5b556d1ffe..d1e1527831 100644 --- a/magnum/tests/unit/api/controllers/v1/test_magnum_service.py +++ b/magnum/tests/unit/api/controllers/v1/test_magnum_service.py @@ -10,9 +10,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - -import json - import mock from magnum.api.controllers.v1 import magnum_services as mservice @@ -96,7 +93,7 @@ class TestMagnumServiceEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_pod.py b/magnum/tests/unit/api/controllers/v1/test_pod.py index 3111e0539b..b75dd25a7f 100644 --- a/magnum/tests/unit/api/controllers/v1/test_pod.py +++ b/magnum/tests/unit/api/controllers/v1/test_pod.py @@ -11,7 +11,6 @@ # limitations under the License. import datetime -import json import mock from oslo_config import cfg @@ -93,7 +92,7 @@ class TestListPod(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_show') def test_get_one_by_name_multiple_pod(self, mock_pod_show): @@ -108,7 +107,7 @@ class TestListPod(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_list') def test_get_all_with_pagination_marker(self, mock_pod_list): @@ -236,7 +235,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_internal_field(self): response = self.patch_json( @@ -245,7 +244,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_non_existent_pod(self): response = self.patch_json( @@ -256,7 +255,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_update') @mock.patch.object(api_pod.Pod, 'parse_manifest') @@ -280,7 +279,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_update') @mock.patch.object(rpcapi.API, 'pod_show') @@ -311,7 +310,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_bay_uuid(self): response = self.patch_json( @@ -320,7 +319,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_internal_field(self): response = self.patch_json( @@ -329,7 +328,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_non_existent_property(self): response = self.patch_json( @@ -338,7 +337,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_code) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_show') @mock.patch.object(rpcapi.API, 'pod_update') @@ -475,7 +474,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/pods', pdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_pod_with_invalid_manifest(self): pdict = apiutils.pod_post_data() @@ -483,7 +482,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/pods', pdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_pod_no_manifest(self): pdict = apiutils.pod_post_data() @@ -491,7 +490,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/pods', pdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_pod_no_id_in_manifest(self): pdict = apiutils.pod_post_data() @@ -499,7 +498,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/pods', pdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestDelete(api_base.FunctionalTest): @@ -520,7 +519,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_delete') @mock.patch.object(rpcapi.API, 'pod_show') @@ -534,7 +533,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_delete') def test_delete_pod_by_name_not_found(self, mock_pod_delete): @@ -545,7 +544,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_delete') def test_delete_multiple_pod_by_name(self, mock_pod_delete): @@ -558,7 +557,7 @@ class TestDelete(api_base.FunctionalTest): response = self.delete('/pods/test_pod', expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'pod_delete') def test_delete_pod_not_found(self, mock_pod_delete): @@ -569,7 +568,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestPodPolicyEnforcement(api_base.FunctionalTest): @@ -581,7 +580,7 @@ class TestPodPolicyEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_replicationcontroller.py b/magnum/tests/unit/api/controllers/v1/test_replicationcontroller.py index d4d65bf39a..20ddb92768 100644 --- a/magnum/tests/unit/api/controllers/v1/test_replicationcontroller.py +++ b/magnum/tests/unit/api/controllers/v1/test_replicationcontroller.py @@ -11,7 +11,6 @@ # limitations under the License. import datetime -import json import mock from oslo_config import cfg @@ -82,7 +81,7 @@ class TestListRC(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_show') def test_get_one_by_name_multiple_rc(self, mock_rc_show): @@ -99,7 +98,7 @@ class TestListRC(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_list') def test_get_all_with_pagination_marker(self, mock_rc_list): @@ -257,7 +256,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_internal_field(self): response = self.patch_json( @@ -266,7 +265,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_replace_non_existent_rc(self): response = self.patch_json( @@ -278,7 +277,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_update') @mock.patch.object(api_rc.ReplicationController, 'parse_manifest') @@ -301,7 +300,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_update') @mock.patch.object(rpcapi.API, 'rc_show') @@ -331,7 +330,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_bay_uuid(self): response = self.patch_json('/rcs/%s/%s' % (self.rc.uuid, @@ -340,7 +339,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_internal_field(self): response = self.patch_json('/rcs/%s/%s' % (self.rc.uuid, @@ -349,7 +348,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_non_existent_property(self): response = self.patch_json( @@ -358,7 +357,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_code) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_show') @mock.patch.object(rpcapi.API, 'rc_update') @@ -491,7 +490,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/rcs', rc_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_rc_with_invalid_manifest(self): rc_dict = apiutils.rc_post_data() @@ -499,7 +498,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/rcs', rc_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_rc_no_manifest(self): rc_dict = apiutils.rc_post_data() @@ -507,7 +506,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/rcs', rc_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_rc_no_id_in_manifest(self): rc_dict = apiutils.rc_post_data() @@ -515,7 +514,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/rcs', rc_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestDelete(api_base.FunctionalTest): @@ -536,7 +535,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_delete') def test_delete_rc_not_found(self, mock_rc_delete): @@ -547,7 +546,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_delete') def test_delete_rc_with_name_not_found(self, mock_rc_delete): @@ -558,7 +557,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'rc_delete') def test_delete_rc_with_name(self, mock_rc_delete): @@ -579,7 +578,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestRCEnforcement(api_base.FunctionalTest): @@ -591,7 +590,7 @@ class TestRCEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_service.py b/magnum/tests/unit/api/controllers/v1/test_service.py index 736c413762..df5d203c51 100644 --- a/magnum/tests/unit/api/controllers/v1/test_service.py +++ b/magnum/tests/unit/api/controllers/v1/test_service.py @@ -11,7 +11,6 @@ # limitations under the License. import datetime -import json import mock from oslo_config import cfg @@ -93,7 +92,7 @@ class TestListService(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_show') def test_get_one_by_name_multiple_service(self, mock_service_show): @@ -110,7 +109,7 @@ class TestListService(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_list') def test_get_all_with_pagination_marker(self, mock_service_list): @@ -251,7 +250,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_update') def test_replace_internal_field(self, mock_service_update): @@ -263,7 +262,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_update') def test_replace_non_existent_service(self, mock_service_update): @@ -278,7 +277,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_update') @mock.patch.object(api_service.Service, 'parse_manifest') @@ -303,7 +302,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_uuid(self): response = self.patch_json( @@ -312,7 +311,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_bay_uuid(self): response = self.patch_json( @@ -321,7 +320,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_internal_field(self): response = self.patch_json( @@ -330,7 +329,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_remove_non_existent_property(self): response = self.patch_json( @@ -339,7 +338,7 @@ class TestPatch(api_base.FunctionalTest): expect_errors=True) self.assertEqual(400, response.status_code) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_show') @mock.patch.object(rpcapi.API, 'service_update') @@ -487,7 +486,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_service_no_manifest(self): sdict = apiutils.service_post_data() @@ -495,7 +494,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_service_invalid_manifest(self): sdict = apiutils.service_post_data() @@ -503,7 +502,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_service_no_id_in_manifest(self): sdict = apiutils.service_post_data() @@ -511,7 +510,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestDelete(api_base.FunctionalTest): @@ -535,7 +534,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_delete') @mock.patch.object(rpcapi.API, 'service_show') @@ -549,7 +548,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_delete') @mock.patch.object(rpcapi.API, 'service_show') @@ -576,7 +575,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) @mock.patch.object(rpcapi.API, 'service_delete') def test_delete_multiple_service_by_name(self, mock_service_delete): @@ -591,7 +590,7 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(500, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) class TestServiceEnforcement(api_base.FunctionalTest): @@ -603,7 +602,7 @@ class TestServiceEnforcement(api_base.FunctionalTest): self.assertEqual('application/json', response.content_type) self.assertTrue( "Policy doesn't allow %s to be performed." % rule, - json.loads(response.json['error_message'])['faultstring']) + response.json['errors'][0]['detail']) def test_policy_disallow_get_all(self): self._common_policy_check( diff --git a/magnum/tests/unit/api/controllers/v1/test_types.py b/magnum/tests/unit/api/controllers/v1/test_types.py index af81084168..b9d96a5415 100644 --- a/magnum/tests/unit/api/controllers/v1/test_types.py +++ b/magnum/tests/unit/api/controllers/v1/test_types.py @@ -96,7 +96,6 @@ class TestJsonPatchType(base.FunctionalTest): patch = [{'path': '/internal', 'op': 'replace', 'value': 'foo'}] ret = self._patch_json(patch, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_mandatory_attr(self): patch = [{'op': 'replace', 'path': '/mandatory', 'value': 'foo'}] @@ -108,43 +107,36 @@ class TestJsonPatchType(base.FunctionalTest): patch = [{'op': 'remove', 'path': '/mandatory'}] ret = self._patch_json(patch, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_missing_required_fields_path(self): missing_path = [{'op': 'remove'}] ret = self._patch_json(missing_path, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_missing_required_fields_op(self): missing_op = [{'path': '/foo'}] ret = self._patch_json(missing_op, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_invalid_op(self): patch = [{'path': '/foo', 'op': 'invalid'}] ret = self._patch_json(patch, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_invalid_path(self): patch = [{'path': 'invalid-path', 'op': 'remove'}] ret = self._patch_json(patch, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_cannot_add_with_no_value(self): patch = [{'path': '/extra/foo', 'op': 'add'}] ret = self._patch_json(patch, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) def test_cannot_replace_with_no_value(self): patch = [{'path': '/foo', 'op': 'replace'}] ret = self._patch_json(patch, True) self.assertEqual(400, ret.status_int) - self.assertTrue(ret.json['faultstring']) class TestMultiType(base.FunctionalTest): diff --git a/magnum/tests/unit/api/controllers/v1/test_x509keypair.py b/magnum/tests/unit/api/controllers/v1/test_x509keypair.py index d8922f7f18..cd43371c86 100644 --- a/magnum/tests/unit/api/controllers/v1/test_x509keypair.py +++ b/magnum/tests/unit/api/controllers/v1/test_x509keypair.py @@ -80,7 +80,7 @@ class TestListX509KeyPair(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_get_one_by_name_multiple_x509keypair(self): obj_utils.create_test_x509keypair(self.context, @@ -93,7 +93,7 @@ class TestListX509KeyPair(api_base.FunctionalTest): expect_errors=True) self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_detail(self): x509keypair = obj_utils.create_test_x509keypair(self.context) @@ -236,7 +236,7 @@ class TestPost(api_base.FunctionalTest): response = self.post_json('/x509keypairs', cdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_create_x509keypair_with_bay_name(self): cdict = apiutils.x509keypair_post_data(bay_uuid=self.bay.name) @@ -268,20 +268,20 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_x509keypair_not_found(self): uuid = utils.generate_uuid() response = self.delete('/x509keypairs/%s' % uuid, expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_x509keypair_with_name_not_found(self): response = self.delete('/x509keypairs/not_found', expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) def test_delete_x509keypair_with_name(self): response = self.delete('/x509keypairs/%s' % self.x509keypair.name, @@ -299,4 +299,4 @@ class TestDelete(api_base.FunctionalTest): expect_errors=True) self.assertEqual(409, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertTrue(response.json['error_message']) + self.assertTrue(response.json['errors']) diff --git a/magnum/tests/unit/api/test_hooks.py b/magnum/tests/unit/api/test_hooks.py index 0219fe16a4..f7b9a9aa5a 100644 --- a/magnum/tests/unit/api/test_hooks.py +++ b/magnum/tests/unit/api/test_hooks.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import six import mock @@ -90,7 +89,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): response = self.get_json('/', path_prefix='', expect_errors=True) - actual_msg = json.loads(response.json['error_message'])['faultstring'] + actual_msg = response.json['errors'][0]['detail'] self.assertEqual(self.MSG_WITHOUT_TRACE, actual_msg) def test_hook_remote_error_success(self): @@ -112,7 +111,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): else: expected_msg = ("Remote error: %s %s" % (test_exc_type, self.MSG_WITHOUT_TRACE) + "\n['") - actual_msg = json.loads(response.json['error_message'])['faultstring'] + actual_msg = response.json['errors'][0]['detail'] self.assertEqual(expected_msg, actual_msg) def test_hook_without_traceback(self): @@ -121,7 +120,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): response = self.get_json('/', path_prefix='', expect_errors=True) - actual_msg = json.loads(response.json['error_message'])['faultstring'] + actual_msg = response.json['errors'][0]['detail'] self.assertEqual(msg, actual_msg) def test_hook_server_debug_on_serverfault(self): @@ -130,8 +129,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): response = self.get_json('/', path_prefix='', expect_errors=True) - actual_msg = json.loads( - response.json['error_message'])['faultstring'] + actual_msg = response.json['errors'][0]['detail'] self.assertEqual(self.MSG_WITHOUT_TRACE, actual_msg) def test_hook_server_debug_on_clientfault(self): @@ -142,6 +140,5 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): response = self.get_json('/', path_prefix='', expect_errors=True) - actual_msg = json.loads( - response.json['error_message'])['faultstring'] + actual_msg = response.json['errors'][0]['detail'] self.assertEqual(self.MSG_WITH_TRACE, actual_msg)