summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-07-26 22:51:23 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-07-31 13:51:28 +0800
commitc3c9891ddd60a1e6af61d7ab149f2f5b4a74227d (patch)
tree5949c7d255cae1f96ae2a5194ba67c568344dbd7
parent1cf39ee5c3739c18fed78946532438550f56356f (diff)
downloadoslo-middleware-c3c9891ddd60a1e6af61d7ab149f2f5b4a74227d.tar.gz
Fix exception in json response under py35
charset is required when response with body Closes-Bug: #1707127 Change-Id: I9921c67866d252f972954eed5afbc90389e06c3f
-rw-r--r--oslo_middleware/healthcheck/__init__.py1
-rw-r--r--oslo_middleware/tests/test_healthcheck.py8
-rw-r--r--test-requirements.txt1
3 files changed, 10 insertions, 0 deletions
diff --git a/oslo_middleware/healthcheck/__init__.py b/oslo_middleware/healthcheck/__init__.py
index c85e1ac..13985cb 100644
--- a/oslo_middleware/healthcheck/__init__.py
+++ b/oslo_middleware/healthcheck/__init__.py
@@ -558,4 +558,5 @@ Reason
functor = self._accept_to_functor[accept_type]
body, content_type = functor(results, healthy)
return webob.response.Response(status=status, body=body,
+ charset='UTF-8',
content_type=content_type)
diff --git a/oslo_middleware/tests/test_healthcheck.py b/oslo_middleware/tests/test_healthcheck.py
index 793a895..9220ea4 100644
--- a/oslo_middleware/tests/test_healthcheck.py
+++ b/oslo_middleware/tests/test_healthcheck.py
@@ -18,6 +18,7 @@ import time
import mock
from oslo_config import fixture as config
+from oslo_serialization import jsonutils
from oslotest import base as test_base
import requests
import webob.dec
@@ -192,3 +193,10 @@ class HealthcheckTests(test_base.BaseTestCase):
expected_body=b'DISABLED BY FILE',
server_port=81)
self.assertIn('disable_by_files_ports', self.app._backends.names())
+
+ def test_json_response(self):
+ expected_body = jsonutils.dumps({'detailed': False, 'reasons': []},
+ indent=4,
+ sort_keys=True).encode('utf-8')
+ self._do_test(expected_body=expected_body,
+ accept='application/json')
diff --git a/test-requirements.txt b/test-requirements.txt
index fb4395f..45667bb 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -11,3 +11,4 @@ sphinx>=1.6.2 # BSD
testtools>=1.4.0 # MIT
coverage!=4.4,>=4.0 # Apache-2.0
reno!=2.3.1,>=1.8.0 # Apache-2.0
+oslo.serialization>=1.10.0,!=2.19.1 # Apache-2.0