예제 #1
0
def create_resource(options):
    """
    Resources resource factory method.
    """
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    return wsgi.Resource(ResourceController(options), deserializer, serializer)
예제 #2
0
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)
예제 #3
0
def create_resource(options):
    """
    Software deployments resource factory method.
    """
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    return wsgi.Resource(SoftwareDeploymentController(options), deserializer,
                         serializer)
예제 #4
0
 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
예제 #5
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"}')
예제 #6
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)
예제 #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)