예제 #1
0
 def test_default(self):
     fixture = {"key": "value"}
     response = webob.Response()
     wsgi.JSONResponseSerializer().default(response, fixture)
     self.assertEqual(response.status_int, 200)
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.body, '{"key": "value"}')
예제 #2
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])
예제 #3
0
 def test_default(self):
     fixture = {"key": "value"}
     response = webob.Response()
     wsgi.JSONResponseSerializer().default(response, fixture)
     self.assertEqual(response.status_int, 200)
     content_types = filter(lambda h: h[0] == 'Content-Type',
                            response.headerlist)
     self.assertEqual(len(content_types), 1)
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.body, '{"key": "value"}')
예제 #4
0
 def test_default(self):
     fixture = {"key": "value"}
     response = webob.Response()
     wsgi.JSONResponseSerializer().default(response, fixture)
     self.assertEqual(http.OK, 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)
예제 #5
0
파일: test_rpc.py 프로젝트: schatt/glance
def create_api():
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    controller = rpc.Controller()
    controller.register(FakeResource())
    res = wsgi.Resource(controller, deserializer, serializer)

    mapper = routes.Mapper()
    mapper.connect("/rpc",
                   controller=res,
                   conditions=dict(method=["POST"]),
                   action="__call__")
    return test_utils.FakeAuthMiddleware(wsgi.Router(mapper), is_admin=True)
예제 #6
0
 def test_to_json_with_set(self):
     fixture = set(["foo"])
     expected = '["foo"]'
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     self.assertEqual(actual, expected)
예제 #7
0
 def test_to_json_with_date_format_value(self):
     fixture = {"date": datetime.datetime(1, 3, 8, 2)}
     expected = '{"date": "0001-03-08T02:00:00"}'
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     self.assertEqual(actual, expected)
예제 #8
0
 def test_to_json(self):
     fixture = {"key": "value"}
     expected = '{"key": "value"}'
     actual = wsgi.JSONResponseSerializer().to_json(fixture)
     self.assertEqual(actual, expected)
예제 #9
0
def create_resource():
    """Image members resource factory method"""
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    return wsgi.Resource(Controller(), deserializer, serializer)
예제 #10
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)
     self.assertEqual(actual, expected)
예제 #11
0
파일: images.py 프로젝트: nicoleLiu/glance
def create_resource(options):
    """Images resource factory method."""
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    return wsgi.Resource(Controller(options), deserializer, serializer)