def init_request_handler(self, rh_cls, view_type): global app if view_type == 'list': rq = rh_cls.as_list() elif view_type == 'detail': rq = rh_cls.as_detail() # compose a fake incoming request fake_connection = None # after tornado 4.1, it's not allowed to build a RequestHandler without a connection. if _newer_or_equal_((4, 0, 0, 0)): ios = IOStream(socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)) context = None # there is a bug in these 2 version that would fail when # context is None if _equal_((4, 0, 1)) or _equal_((4, 0, 2)): context = httpserver._HTTPRequestContext(ios, None, None) fake_connection = HTTP1Connection(ios, False, context=context) fake_request = httpserver.HTTPRequest('GET', '/fake', body='test123', connection=fake_connection) self.new_handler = rq(app, fake_request)
def setUp(self): # Set up a server request object. self.request = httpserver.HTTPRequest( 'POST', '/test/', headers={'Content-Type': 'application/json'}, body='hello')
def init_request_handler(self, rh_cls, view_type): global app if view_type == 'list': rq = rh_cls.as_list() elif view_type == 'detail': rq = rh_cls.as_detail() fake_request = httpserver.HTTPRequest('GET', '/fake', body='test123') self.new_handler = rq(app, fake_request)
def boto_to_tornado(method, path, headers, data, host, connection=None): """ translate boto requests into tornado requests connection should be a FakeTornadoHttpConnection instance """ headers = httpserver.HTTPHeaders() for k, v in headers.iteritems(): headers[k] = v req = httpserver.HTTPRequest(method=method, uri=path, headers=headers, body=data, host=host, remote_ip='127.0.0.1', connection=connection) return req
def test_request_body(self): # An empty body is set to None. original = httpserver.HTTPRequest('GET', '/test/', body='') request = utils.clone_request(original, 'http://example.com/test') self.assertEqual('http://example.com/test', request.url) self.assertIsNone(request.body)