def test_json(self): data = """{"a": { "a1": "1", "a2": "2", "bs": ["1", "2", "3", {"c": {"c1": "1"}}], "d": {"e": "1"}, "f": "1"}}""" as_dict = { 'body': { 'a': { 'a1': '1', 'a2': '2', 'bs': ['1', '2', '3', { 'c': { 'c1': '1' } }], 'd': { 'e': '1' }, 'f': '1', }, }, } deserializer = wsgi.JSONDeserializer() self.assertEqual(deserializer.deserialize(data), as_dict)
def test_json_invalid_utf8(self): """Send invalid utf-8 to JSONDeserializer.""" data = b"""{"segment": { "name": "\xf0\x28\x8c\x28", "recovery_method": "auto", "description": "compute hosts with shared storage enabled." "service_type": "COMPUTE_HOST"}} """ deserializer = wsgi.JSONDeserializer() self.assertRaises(exception.MalformedRequestBody, deserializer.deserialize, data)
def test_json_valid_utf8(self): data = b"""{"segment": {"recovery_method": "auto", "name": "\xe6\xa6\x82\xe5\xbf\xb5", "service_type": "COMPUTE_HOST" }} """ as_dict = { 'body': { u'segment': {u'recovery_method': 'auto', u'name': u'\u6982\u5ff5', u'service_type': u'COMPUTE_HOST' } } } deserializer = wsgi.JSONDeserializer() self.assertEqual(deserializer.deserialize(data), as_dict)