py3: port healthcheck
Typed "b" in a half-dozen places and fixed a typo in a test name. Change-Id: Idcb8b2eeef5b545eb0944cc22b7c7961e8c2f8f0
This commit is contained in:
parent
0edfb879a7
commit
50ea4e1e08
@ -35,11 +35,11 @@ class HealthCheckMiddleware(object):
|
||||
|
||||
def GET(self, req):
|
||||
"""Returns a 200 response with "OK" in the body."""
|
||||
return Response(request=req, body="OK", content_type="text/plain")
|
||||
return Response(request=req, body=b"OK", content_type="text/plain")
|
||||
|
||||
def DISABLED(self, req):
|
||||
"""Returns a 503 response with "DISABLED BY FILE" in the body."""
|
||||
return Response(request=req, status=503, body="DISABLED BY FILE",
|
||||
return Response(request=req, status=503, body=b"DISABLED BY FILE",
|
||||
content_type="text/plain")
|
||||
|
||||
def __call__(self, env, start_response):
|
||||
|
@ -51,21 +51,21 @@ class TestHealthCheck(unittest.TestCase):
|
||||
app = self.get_app(FakeApp(), {})
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(['200 OK'], self.got_statuses)
|
||||
self.assertEqual(resp, ['OK'])
|
||||
self.assertEqual(resp, [b'OK'])
|
||||
|
||||
def test_healtcheck_pass(self):
|
||||
def test_healthcheck_pass(self):
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
app = self.get_app(FakeApp(), {})
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(['200 OK'], self.got_statuses)
|
||||
self.assertEqual(resp, ['FAKE APP'])
|
||||
self.assertEqual(resp, [b'FAKE APP'])
|
||||
|
||||
def test_healthcheck_pass_not_disabled(self):
|
||||
req = Request.blank('/healthcheck', environ={'REQUEST_METHOD': 'GET'})
|
||||
app = self.get_app(FakeApp(), {}, disable_path=self.disable_path)
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(['200 OK'], self.got_statuses)
|
||||
self.assertEqual(resp, ['OK'])
|
||||
self.assertEqual(resp, [b'OK'])
|
||||
|
||||
def test_healthcheck_pass_disabled(self):
|
||||
open(self.disable_path, 'w')
|
||||
@ -73,7 +73,7 @@ class TestHealthCheck(unittest.TestCase):
|
||||
app = self.get_app(FakeApp(), {}, disable_path=self.disable_path)
|
||||
resp = app(req.environ, self.start_response)
|
||||
self.assertEqual(['503 Service Unavailable'], self.got_statuses)
|
||||
self.assertEqual(resp, ['DISABLED BY FILE'])
|
||||
self.assertEqual(resp, [b'DISABLED BY FILE'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
1
tox.ini
1
tox.ini
@ -38,6 +38,7 @@ commands =
|
||||
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_healthcheck.py \
|
||||
test/unit/common/middleware/test_proxy_logging.py \
|
||||
test/unit/common/ring \
|
||||
test/unit/common/test_constraints.py \
|
||||
|
Loading…
Reference in New Issue
Block a user