diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-08 19:20:12 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-08 19:20:12 +0000 |
| commit | 5df2184cd0424e7034464ff387a86266b93e9bf5 (patch) | |
| tree | 59c52bc1c377463cdca4e004b3e2853c876c743f | |
| parent | 1230c7a62760a13d00b58c7fc9c7fa50ab231c61 (diff) | |
| parent | e3ddc41f1b02644d7fae4482c4beade7f27e58de (diff) | |
| download | oslo-5df2184cd0424e7034464ff387a86266b93e9bf5.tar.gz oslo-5df2184cd0424e7034464ff387a86266b93e9bf5.tar.xz oslo-5df2184cd0424e7034464ff387a86266b93e9bf5.zip | |
Merge "JSONDictSerializer encode objects to unicode"
| -rw-r--r-- | openstack/common/wsgi.py | 2 | ||||
| -rw-r--r-- | tests/unit/test_wsgi.py | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/openstack/common/wsgi.py b/openstack/common/wsgi.py index f52fca0..1d6d9df 100644 --- a/openstack/common/wsgi.py +++ b/openstack/common/wsgi.py @@ -387,7 +387,7 @@ class JSONDictSerializer(DictSerializer): if isinstance(obj, datetime.datetime): _dtime = obj - datetime.timedelta(microseconds=obj.microsecond) return _dtime.isoformat() - return obj + return unicode(obj) return jsonutils.dumps(data, default=sanitizer) diff --git a/tests/unit/test_wsgi.py b/tests/unit/test_wsgi.py index 07c85d5..c621a8c 100644 --- a/tests/unit/test_wsgi.py +++ b/tests/unit/test_wsgi.py @@ -179,6 +179,17 @@ class JSONDictSerializerTest(unittest.TestCase): result = result.replace('\n', '').replace(' ', '') self.assertEqual(result, expected_json) + def test_object_unicode(self): + class TestUnicode: + def __unicode__(self): + return u'TestUnicode' + input_dict = dict(cls=TestUnicode()) + expected_str = '{"cls":"TestUnicode"}' + serializer = wsgi.JSONDictSerializer() + result = serializer.serialize(input_dict) + result = result.replace('\n', '').replace(' ', '') + self.assertEqual(result, expected_str) + class TextDeserializerTest(unittest.TestCase): |
