120
121
self.assertTrue('<computeFault' in resp.body, resp.body)
121
122
self.assertEqual(resp.status_int, 500, resp.body)
124
def _do_test_exception_safety_reflected_in_faults(self, expose):
125
class ExceptionWithSafety(exception.NovaException):
130
raise ExceptionWithSafety('some explanation')
132
api = self._wsgi_app(fail)
133
resp = webob.Request.blank('/').get_response(api)
134
self.assertTrue('{"computeFault' in resp.body, resp.body)
135
expected = ('ExceptionWithSafety: some explanation' if expose else
136
'The server has either erred or is incapable '
137
'of performing the requested operation.')
138
self.assertTrue(expected in resp.body, resp.body)
139
self.assertEqual(resp.status_int, 500, resp.body)
141
def test_safe_exceptions_are_described_in_faults(self):
142
self._do_test_exception_safety_reflected_in_faults(True)
144
def test_unsafe_exceptions_are_not_described_in_faults(self):
145
self._do_test_exception_safety_reflected_in_faults(False)
147
def _do_test_exception_mapping(self, exception_type, msg):
150
raise exception_type(msg)
152
api = self._wsgi_app(fail)
153
resp = webob.Request.blank('/').get_response(api)
154
self.assertTrue(msg in resp.body, resp.body)
155
self.assertEqual(resp.status_int, exception_type.code, resp.body)
157
if hasattr(exception_type, 'headers'):
158
for (key, value) in exception_type.headers.iteritems():
159
self.assertTrue(key in resp.headers)
160
self.assertEquals(resp.headers[key], value)
162
def test_quota_error_mapping(self):
163
self._do_test_exception_mapping(exception.QuotaError, 'too many used')
165
def test_non_nova_notfound_exception_mapping(self):
166
class ExceptionWithCode(Exception):
169
self._do_test_exception_mapping(ExceptionWithCode,
172
def test_non_nova_exception_mapping(self):
173
class ExceptionWithCode(Exception):
176
self._do_test_exception_mapping(ExceptionWithCode,
177
'Expectation failed')
179
def test_exception_with_none_code_throws_500(self):
180
class ExceptionWithNoneCode(Exception):
183
msg = 'Internal Server Error'
187
raise ExceptionWithNoneCode()
189
api = self._wsgi_app(fail)
190
resp = webob.Request.blank('/').get_response(api)
191
self.assertEqual(500, resp.status_int)
123
193
def test_request_id_in_response(self):
124
194
req = webob.Request.blank('/')
125
195
req.method = 'GET'