示例#1
0
 def test_to_json_with_more_deep_format(self):
     fixture = {"is_public": True, "name": [{"name1": "test"}]}
     expected = {"is_public": True, "name": [{"name1": "test"}]}
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     actual = jsonutils.loads(actual)
     for k in expected:
         self.assertEqual(expected[k], actual[k])
示例#2
0
 def test_default(self):
     fixture = {"key": "value"}
     response = webob.Response()
     wsgi.JSONResponseSerializer().default(response, fixture)
     self.assertEqual(200, response.status_int)
     content_types = [
         h for h in response.headerlist if h[0] == 'Content-Type'
     ]
     self.assertEqual(1, len(content_types))
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(b'{"key": "value"}', response.body)
示例#3
0
def create_resource():
    """Image members resource factory method"""
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    return wsgi.Resource(Controller(), deserializer, serializer)
示例#4
0
 def test_to_json_with_set(self):
     fixture = set(["foo"])
     expected = b'["foo"]'
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     self.assertEqual(expected, actual)
示例#5
0
 def test_to_json_with_date_format_value(self):
     fixture = {"date": datetime.datetime(1901, 3, 8, 2)}
     expected = b'{"date": "1901-03-08T02:00:00.000000"}'
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     self.assertEqual(expected, actual)
示例#6
0
 def test_to_json(self):
     fixture = {"key": "value"}
     expected = b'{"key": "value"}'
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     self.assertEqual(expected, actual)