From c3c9891ddd60a1e6af61d7ab149f2f5b4a74227d Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Wed, 26 Jul 2017 22:51:23 +0800 Subject: Fix exception in json response under py35 charset is required when response with body Closes-Bug: #1707127 Change-Id: I9921c67866d252f972954eed5afbc90389e06c3f --- oslo_middleware/healthcheck/__init__.py | 1 + oslo_middleware/tests/test_healthcheck.py | 8 ++++++++ test-requirements.txt | 1 + 3 files changed, 10 insertions(+) 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 -- cgit v1.2.1