Merge "py3: port catch_errors"
This commit is contained in:
commit
84ddb8c1ec
@ -42,7 +42,7 @@ class CatchErrorsContext(WSGIContext):
|
||||
except: # noqa
|
||||
self.logger.exception(_('Error: An error occurred'))
|
||||
resp = HTTPServerError(request=Request(env),
|
||||
body='An error occurred',
|
||||
body=b'An error occurred',
|
||||
content_type='text/plain')
|
||||
resp.headers['X-Trans-Id'] = trans_id
|
||||
resp.headers['X-Openstack-Request-Id'] = trans_id
|
||||
|
@ -38,7 +38,7 @@ class FakeApp(object):
|
||||
raise StrangeException('whoa')
|
||||
raise Exception('An error occurred')
|
||||
if self.body_iter is None:
|
||||
return ["FAKE APP"]
|
||||
return [b"FAKE APP"]
|
||||
else:
|
||||
return self.body_iter
|
||||
|
||||
@ -61,13 +61,13 @@ class TestCatchErrors(unittest.TestCase):
|
||||
app = catch_errors.CatchErrorMiddleware(FakeApp(), {})
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(list(resp), ['FAKE APP'])
|
||||
self.assertEqual(list(resp), [b'FAKE APP'])
|
||||
|
||||
def test_catcherrors(self):
|
||||
app = catch_errors.CatchErrorMiddleware(FakeApp(True), {})
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(list(resp), ['An error occurred'])
|
||||
self.assertEqual(list(resp), [b'An error occurred'])
|
||||
|
||||
def test_trans_id_header_pass(self):
|
||||
self.assertIsNone(self.logger.txn_id)
|
||||
@ -90,7 +90,7 @@ class TestCatchErrors(unittest.TestCase):
|
||||
FakeApp(body_iter=(int(x) for x in 'abcd')), {})
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(list(resp), ['An error occurred'])
|
||||
self.assertEqual(list(resp), [b'An error occurred'])
|
||||
|
||||
def test_trans_id_header_suffix(self):
|
||||
self.assertIsNone(self.logger.txn_id)
|
||||
@ -135,7 +135,7 @@ class TestCatchErrors(unittest.TestCase):
|
||||
app = catch_errors.CatchErrorMiddleware(FakeApp(error='strange'), {})
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(list(resp), ['An error occurred'])
|
||||
self.assertEqual(list(resp), [b'An error occurred'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
1
tox.ini
1
tox.ini
@ -36,6 +36,7 @@ commands =
|
||||
test/unit/cli/test_relinker.py \
|
||||
test/unit/cli/test_ring_builder_analyzer.py \
|
||||
test/unit/cli/test_ringbuilder.py \
|
||||
test/unit/common/middleware/test_catch_errors.py \
|
||||
test/unit/common/middleware/test_gatekeeper.py \
|
||||
test/unit/common/middleware/test_proxy_logging.py \
|
||||
test/unit/common/ring \
|
||||
|
Loading…
Reference in New Issue
Block a user