From 3920b88daaaa6c9c819b604f2094305e507a41cf Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Thu, 21 Jun 2018 17:23:41 -0700 Subject: [PATCH] py3: port catch_errors Today's diff is brought to you by the letter "b". Change-Id: I074c1ff3f1232a899c101f2856dff4a881a6fe77 --- swift/common/middleware/catch_errors.py | 2 +- test/unit/common/middleware/test_catch_errors.py | 10 +++++----- tox.ini | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/swift/common/middleware/catch_errors.py b/swift/common/middleware/catch_errors.py index 6e9334795a..a1cc4a4a58 100644 --- a/swift/common/middleware/catch_errors.py +++ b/swift/common/middleware/catch_errors.py @@ -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 diff --git a/test/unit/common/middleware/test_catch_errors.py b/test/unit/common/middleware/test_catch_errors.py index 36996b457e..a962ddc3c7 100644 --- a/test/unit/common/middleware/test_catch_errors.py +++ b/test/unit/common/middleware/test_catch_errors.py @@ -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__': diff --git a/tox.ini b/tox.ini index 27926f3d7d..747e3e077c 100644 --- a/tox.ini +++ b/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 \