Example #1
0
 def test_default_with_body(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = b'{"key": "value"}'
     actual = rpc.RPCJSONDeserializer().default(request)
     expected = {"body": {"key": "value"}}
     self.assertEqual(expected, actual)
Example #2
0
 def test_has_body_has_transfer_encoding(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = b'fake_body'
     request.headers['transfer-encoding'] = ''
     self.assertIn('transfer-encoding', request.headers)
     self.assertTrue(rpc.RPCJSONDeserializer().has_body(request))
Example #3
0
def create_api():
    deserializer = rpc.RPCJSONDeserializer()
    serializer = rpc.RPCJSONSerializer()
    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)
Example #4
0
 def test_to_json_with_date_format_value(self):
     fixture = ('{"date": {"_value": "1900-03-08T02:00:00.000000",'
                '"_type": "datetime"}}')
     expected = {"date": datetime.datetime(1900, 3, 8, 2)}
     actual = rpc.RPCJSONDeserializer().from_json(fixture)
     self.assertEqual(expected, actual)
Example #5
0
 def test_from_json_malformed(self):
     fixture = 'kjasdklfjsklajf'
     self.assertRaises(webob.exc.HTTPBadRequest,
                       rpc.RPCJSONDeserializer().from_json, fixture)
Example #6
0
 def test_default_no_body(self):
     request = wsgi.Request.blank('/')
     actual = rpc.RPCJSONDeserializer().default(request)
     expected = {}
     self.assertEqual(expected, actual)
Example #7
0
 def test_from_json(self):
     fixture = '{"key": "value"}'
     expected = {"key": "value"}
     actual = rpc.RPCJSONDeserializer().from_json(fixture)
     self.assertEqual(expected, actual)
Example #8
0
 def test_no_body_no_content_length(self):
     request = wsgi.Request.blank('/')
     self.assertFalse(rpc.RPCJSONDeserializer().has_body(request))
Example #9
0
 def test_has_body_has_content_length(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = b'asdf'
     self.assertIn('Content-Length', request.headers)
     self.assertTrue(rpc.RPCJSONDeserializer().has_body(request))
Example #10
0
 def test_has_body_zero_content_length(self):
     request = wsgi.Request.blank('/')
     request.method = 'POST'
     request.body = b'asdf'
     request.headers['Content-Length'] = 0
     self.assertFalse(rpc.RPCJSONDeserializer().has_body(request))
Example #11
0
def create_resource():
    """Images resource factory method."""
    deserializer = rpc.RPCJSONDeserializer()
    serializer = rpc.RPCJSONSerializer()
    return wsgi.Resource(Controller(), deserializer, serializer)