diff --git a/heat/common/serializers.py b/heat/common/serializers.py
index a4ce8d7bff..9235f6a9c6 100644
--- a/heat/common/serializers.py
+++ b/heat/common/serializers.py
@@ -44,7 +44,7 @@ class JSONResponseSerializer(object):
def default(self, response, result):
response.content_type = 'application/json'
- response.body = self.to_json(result)
+ response.body = six.b(self.to_json(result))
# Escape XML serialization for these keys, as the AWS API defines them as
diff --git a/heat/tests/test_common_serializers.py b/heat/tests/test_common_serializers.py
index 5bbe623bd4..75605a41f1 100644
--- a/heat/tests/test_common_serializers.py
+++ b/heat/tests/test_common_serializers.py
@@ -17,6 +17,9 @@
import collections
import datetime
+from lxml import etree
+from oslo_serialization import jsonutils as json
+import six
import webob
from heat.common import serializers
@@ -46,7 +49,7 @@ class JSONResponseSerializerTest(common.HeatTestCase):
])
expected = '{"is_public": true, "name": [{"name1": "test"}]}'
actual = serializers.JSONResponseSerializer().to_json(fixture)
- self.assertEqual(expected, actual)
+ self.assertEqual(json.loads(expected), json.loads(actual))
def test_to_json_with_objects(self):
fixture = collections.OrderedDict([
@@ -55,7 +58,7 @@ class JSONResponseSerializerTest(common.HeatTestCase):
])
expected = '{"is_public": true, "value": "(1+2j)"}'
actual = serializers.JSONResponseSerializer().to_json(fixture)
- self.assertEqual(expected, actual)
+ self.assertEqual(json.loads(expected), json.loads(actual))
def test_default(self):
fixture = {"key": "value"}
@@ -66,28 +69,36 @@ class JSONResponseSerializerTest(common.HeatTestCase):
response.headerlist))
self.assertEqual(1, len(content_types))
self.assertEqual('application/json', response.content_type)
- self.assertEqual('{"key": "value"}', response.body)
+ self.assertEqual(b'{"key": "value"}', response.body)
class XMLResponseSerializerTest(common.HeatTestCase):
+ def _recursive_dict(self, element):
+ return element.tag, dict(
+ map(self._recursive_dict, element)) or element.text
+
def test_to_xml(self):
fixture = {"key": "value"}
- expected = 'value'
+ expected = b'value'
actual = serializers.XMLResponseSerializer().to_xml(fixture)
self.assertEqual(expected, actual)
def test_to_xml_with_date_format_value(self):
fixture = {"date": datetime.datetime(1, 3, 8, 2)}
- expected = '0001-03-08 02:00:00'
+ expected = b'0001-03-08 02:00:00'
actual = serializers.XMLResponseSerializer().to_xml(fixture)
self.assertEqual(expected, actual)
def test_to_xml_with_list(self):
fixture = {"name": ["1", "2"]}
- expected = '12'
+ expected = b'12'
actual = serializers.XMLResponseSerializer().to_xml(fixture)
- self.assertEqual(expected, actual)
+ actual_xml_tree = etree.XML(actual)
+ actual_xml_dict = self._recursive_dict(actual_xml_tree)
+ expected_xml_tree = etree.XML(expected)
+ expected_xml_dict = self._recursive_dict(expected_xml_tree)
+ self.assertEqual(expected_xml_dict, actual_xml_dict)
def test_to_xml_with_more_deep_format(self):
# Note we expect tree traversal from one root key, which is compatible
@@ -100,11 +111,16 @@ class XMLResponseSerializerTest(common.HeatTestCase):
])])
]))
])
- expected = ('True'
- 'test'
- '')
+ expected = six.b('True'
+ 'test'
+ '')
actual = serializers.XMLResponseSerializer().to_xml(fixture)
- self.assertEqual(expected, actual)
+ actual_xml_tree = etree.XML(actual)
+ actual_xml_dict = self._recursive_dict(actual_xml_tree)
+ expected_xml_tree = etree.XML(expected)
+ expected_xml_dict = self._recursive_dict(expected_xml_tree)
+
+ self.assertEqual(expected_xml_dict, actual_xml_dict)
def test_to_xml_with_json_only_keys(self):
# Certain keys are excluded from serialization because CFN
@@ -116,11 +132,15 @@ class XMLResponseSerializerTest(common.HeatTestCase):
('Metadata', {"name2": "test2"}),
]))
])
- expected = ('True'
- '{"name1": "test"}'
- '{"name2": "test2"}')
+ expected = six.b('True'
+ '{"name1": "test"}'
+ '{"name2": "test2"}')
actual = serializers.XMLResponseSerializer().to_xml(fixture)
- self.assertEqual(expected, actual)
+ actual_xml_tree = etree.XML(actual)
+ actual_xml_dict = self._recursive_dict(actual_xml_tree)
+ expected_xml_tree = etree.XML(expected)
+ expected_xml_dict = self._recursive_dict(expected_xml_tree)
+ self.assertEqual(expected_xml_dict, actual_xml_dict)
def test_default(self):
fixture = {"key": "value"}
@@ -131,4 +151,4 @@ class XMLResponseSerializerTest(common.HeatTestCase):
response.headerlist))
self.assertEqual(1, len(content_types))
self.assertEqual('application/xml', response.content_type)
- self.assertEqual('value', response.body)
+ self.assertEqual(b'value', response.body)
diff --git a/py3-testlist b/py3-testlist
index 13df702e6c..7398163497 100644
--- a/py3-testlist
+++ b/py3-testlist
@@ -93,6 +93,7 @@ heat.tests.test_cloudwatch
heat.tests.test_common_context
heat.tests.test_common_param_utils
heat.tests.test_common_policy
+heat.tests.test_common_serializers
heat.tests.test_common_service_utils
heat.tests.test_constraints
heat.tests.test_crypt