def create_resource(options): """ Resources resource factory method. """ deserializer = wsgi.JSONRequestDeserializer() serializer = wsgi.JSONResponseSerializer() return wsgi.Resource(ResourceController(options), deserializer, serializer)
def create_resource(options): """ Actions action factory method. """ # TODO(zaneb) handle XML based on Content-type/Accepts deserializer = wsgi.JSONRequestDeserializer() serializer = wsgi.JSONResponseSerializer() return wsgi.Resource(ActionController(options), deserializer, serializer)
def create_resource(options): """ Software deployments resource factory method. """ deserializer = wsgi.JSONRequestDeserializer() serializer = wsgi.JSONResponseSerializer() return wsgi.Resource(SoftwareDeploymentController(options), deserializer, serializer)
def __call__(self, req): if req.content_type == 'application/xml': serializer = wsgi.XMLResponseSerializer() else: serializer = wsgi.JSONResponseSerializer() resp = webob.Response(request=req) default_webob_exc = webob.exc.HTTPInternalServerError() resp.status_code = self.error.get('code', default_webob_exc.code) serializer.default(resp, self.error) return resp
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"}')
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)
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)
def test_to_json(self): fixture = {"key": "value"} expected = '{"key": "value"}' actual = wsgi.JSONResponseSerializer().to_json(fixture) self.assertEqual(actual, expected)