示例#1
0
 def test_default_with_body(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = '{"key": "value"}'
     actual = wsgi.JSONRequestDeserializer().default(request)
     expected = {"body": {"key": "value"}}
     self.assertEqual(actual, expected)
示例#2
0
def create_resource(conf):
    """Images resource factory method."""
    deserializer = wsgi.JSONRequestDeserializer()
    serializer = wsgi.JSONResponseSerializer()
    return wsgi.Resource(Controller(conf), deserializer, serializer)
示例#3
0
 def test_default_no_body(self):
     request = wsgi.Request.blank('/')
     actual = wsgi.JSONRequestDeserializer().default(request)
     expected = {}
     self.assertEqual(actual, expected)
示例#4
0
 def test_from_json(self):
     fixture = '{"key": "value"}'
     expected = {"key": "value"}
     actual = wsgi.JSONRequestDeserializer().from_json(fixture)
     self.assertEqual(actual, expected)
示例#5
0
 def test_no_body_no_content_length(self):
     request = wsgi.Request.blank('/')
     self.assertFalse(wsgi.JSONRequestDeserializer().has_body(request))
示例#6
0
 def test_has_body_has_content_length(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = 'asdf'
     self.assertTrue('Content-Length' in request.headers)
     self.assertTrue(wsgi.JSONRequestDeserializer().has_body(request))
示例#7
0
 def test_has_body_zero_content_length(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = 'asdf'
     request.headers['Content-Length'] = 0
     self.assertFalse(wsgi.JSONRequestDeserializer().has_body(request))