Merge "Ensure the correct error message is displayed"

This commit is contained in:
Jenkins 2013-12-18 09:17:25 +00:00 committed by Gerrit Code Review
commit 2b7cd6778d
2 changed files with 21 additions and 0 deletions

View File

@ -74,6 +74,9 @@ class TranslationHook(hooks.PecanHook):
self.local_error = threading.local()
self.local_error.translatable_error = None
def before(self, state):
self.local_error.translatable_error = None
def after(self, state):
if hasattr(state.response, 'translatable_error'):
self.local_error.translatable_error = (

View File

@ -18,9 +18,11 @@
# under the License.
"""Test basic ceilometer-api app
"""
import json
import os
import mock
import wsme
from ceilometer.api import acl
from ceilometer.api import app
@ -207,3 +209,19 @@ class TestApiMiddleware(FunctionalTest):
fault = response.xml.findall('./error/faultstring')
for fault_string in fault:
self.assertEqual(fault_string.text, self.en_US_translated_error)
def test_translated_then_untranslated_error(self):
resp = self.get_json('/alarms/alarm-id-3', expect_errors=True)
self.assertEqual(resp.status_code, 404)
self.assertEqual(json.loads(resp.body)['error_message']
['faultstring'], "Alarm alarm-id-3 Not Found")
with mock.patch('ceilometer.api.controllers.v2.EntityNotFound') \
as CustomErrorClass:
CustomErrorClass.return_value = wsme.exc.ClientSideError(
"untranslated_error", status_code=404)
resp = self.get_json('/alarms/alarm-id-5', expect_errors=True)
self.assertEqual(resp.status_code, 404)
self.assertEqual(json.loads(resp.body)['error_message']
['faultstring'], "untranslated_error")