18
18
from xml.dom import minidom
24
23
from cinder.api import common
25
24
from cinder.api.openstack import wsgi
25
from cinder.openstack.common import gettextutils
26
26
from cinder.openstack.common import jsonutils
27
27
from cinder import test
94
94
resp = req.get_response(raiser)
95
95
self.assertEqual(resp.content_type, "application/xml")
96
96
self.assertEqual(resp.status_int, 404)
97
self.assertTrue('whut?' in resp.body)
97
self.assertIn('whut?', resp.body)
99
99
def test_raise_403(self):
100
100
"""Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
106
106
resp = req.get_response(raiser)
107
107
self.assertEqual(resp.content_type, "application/xml")
108
108
self.assertEqual(resp.status_int, 403)
109
self.assertTrue('resizeNotAllowed' not in resp.body)
110
self.assertTrue('forbidden' in resp.body)
109
self.assertNotIn('resizeNotAllowed', resp.body)
110
self.assertIn('forbidden', resp.body)
112
def test_raise_localized_explanation(self):
114
expl = gettextutils.Message("String with params: %s" % params, 'test')
116
def _mock_translation(msg, locale):
117
return "Mensaje traducido"
119
self.stubs.Set(gettextutils,
120
"get_localized_message", _mock_translation)
124
raise wsgi.Fault(webob.exc.HTTPNotFound(explanation=expl))
126
req = webob.Request.blank('/.xml')
127
resp = req.get_response(raiser)
128
self.assertEqual(resp.content_type, "application/xml")
129
self.assertEqual(resp.status_int, 404)
130
self.assertIn(("Mensaje traducido"), resp.body)
131
self.stubs.UnsetAll()
112
133
def test_fault_has_status_int(self):
113
134
"""Ensure the status_int is set correctly on faults"""
122
143
fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='scram'))
123
144
response = request.get_response(fault)
125
self.assertTrue(common.XML_NS_V1 in response.body)
146
self.assertIn(common.XML_NS_V1, response.body)
126
147
self.assertEqual(response.content_type, "application/xml")
127
148
self.assertEqual(response.status_int, 400)