Example #1
0
 def test_set_input_header(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_input_header=('Header-Name', 'header value'))
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.request.headers['Header-Name'],
                      'header value')
Example #2
0
    def test_set_input_header_with_callable(self):
        def callback(request):
            return ('Header-Name', 'header value')

        request = HTTPServerRequest(method='GET', uri='/')
        exchange = HTTPExchange(request)
        actions = Actions(set_input_header=callback)
        actions.execute_input_actions(exchange)
        self.assertEqual(request.headers['Header-Name'], 'header value')
Example #3
0
    def test_set_status_code_with_callable(self):
        def callback(request):
            return 201

        request = HTTPServerRequest(method='GET', uri='/')
        exchange = HTTPExchange(request)
        actions = Actions(set_status_code=callback)
        actions.execute_input_actions(exchange)
        self.assertEqual(exchange.response.status_code, 201)
Example #4
0
    def test_queue_with_callable(self):
        def callback(request):
            return 'test-queue'

        request = HTTPServerRequest(method='GET', uri='/')
        exchange = HTTPExchange(request)
        actions = Actions(set_redis_queue=callback)
        actions.execute_input_actions(exchange)
        self.assertEqual(exchange.redis_queue, 'test-queue')
Example #5
0
 def test_del_query_string_arg(self):
     request = HTTPServerRequest(method='GET', uri='/?foo1=bar1')
     exchange = HTTPExchange(request)
     actions = Actions(del_query_string_arg="foo1")
     actions.execute_input_actions(exchange)
     args = exchange.request.query_arguments
     self.assertEqual(len(args), 0)
     actions = Actions(del_query_string_arg="foo2")
     actions.execute_input_actions(exchange)
Example #6
0
 def test_set_query_string_arg(self):
     request = HTTPServerRequest(method='GET', uri='/?foo1=bar1')
     exchange = HTTPExchange(request)
     actions = Actions(set_query_string_arg=("foo1", b"bar2"))
     actions.execute_input_actions(exchange)
     args = exchange.request.query_arguments
     self.assertEqual(len(args), 1)
     self.assertEqual(len(args["foo1"]), 1)
     self.assertEqual(args["foo1"][0], b"bar2")
Example #7
0
 def test_del_input_header(self):
     headers = HTTPHeaders()
     headers.add("Header-Name", "header value1")
     request = HTTPServerRequest(method='GET', uri='/', headers=headers)
     exchange = HTTPExchange(request)
     actions = Actions(del_input_header="Header-Name")
     actions.execute_input_actions(exchange)
     keys = list(exchange.request.headers.keys())
     self.assertEquals(len(keys), 0)
     actions = Actions(del_input_header="Header-Name2")
     actions.execute_input_actions(exchange)
Example #8
0
 def test_add_input_header(self):
     headers = HTTPHeaders()
     headers.add("Header-Name", "header value1")
     request = HTTPServerRequest(method='GET', uri='/', headers=headers)
     exchange = HTTPExchange(request)
     actions = Actions(add_input_header=("Header-Name", "header value2"))
     actions.execute_input_actions(exchange)
     values = exchange.request.headers.get_list('Header-Name')
     self.assertEquals(len(values), 2)
     self.assertEquals(values[0], "header value1")
     self.assertEquals(values[1], "header value2")
Example #9
0
 def test_set_status_code(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_status_code=201)
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.response.status_code, 201)
Example #10
0
 def test_set_input_body(self):
     request = HTTPServerRequest(method='PUT', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_input_body=b"foobar")
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.request.body, b"foobar")
Example #11
0
 def test_set_redis_port(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_redis_port=1234)
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.redis_port, 1234)
Example #12
0
 def test_set_remote_ip(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_remote_ip="1.2.3.4")
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.request.remote_ip, "1.2.3.4")
Example #13
0
 def test_set_host(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_host="foobar:8080")
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.request.host, "foobar:8080")
Example #14
0
 def test_set_method(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_method="POST")
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.request.method, "POST")
Example #15
0
 def test_set_path(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_path="/foo")
     actions.execute_input_actions(exchange)
     self.assertEqual(exchange.request.path, "/foo")