Ejemplo n.º 1
0
    def test_static_duplicate_url(self):

        request = request_class(url='/1234')
        request2 = request_class(url='/1234')
        router_instance = Router()
        router_instance.set_url('/1234', self.noop)

        with self.assertRaises(ValueError):
            router_instance.set_url('/1234', self.noop)
Ejemplo n.º 2
0
    def test_one_Blueprint_with_type(self):

        request = request_class(url='/bp/1234-')
        router_instance = Router()
        router_instance.set_url('/<tag>', self.noop)
        router_instance.set_url('/bp/<tag:int>', self.noop)

        with self.assertRaises(LuyAException):
            router_instance.get_mapped_handle(request)

        request = request_class(url='/bp/1234')
        handler, kw = router_instance.get_mapped_handle(request)

        self.assertEqual(kw, {'tag': 1234})
        self.assertEqual(handler, self.noop)
Ejemplo n.º 3
0
    def test_int_url(self):

        request = request_class(url='/123')
        
        router_instance = Router()
        router_instance.set_url('/<tag:int>', self.noop)

        handler, kw = router_instance.get_mapped_handle(request)
        self.assertEqual(kw, {'tag': 123})
        self.assertEqual(handler, self.noop)

        request2 = request_class(url='/12hh3-22')
        
        with self.assertRaises(LuyAException):
            handler, kw = router_instance.get_mapped_handle(request2)
Ejemplo n.º 4
0
    def test_multArg(self):

        request = request_class(url='/1234/12323')
        router_instance = Router()
        router_instance.set_url('/<tag>/<tag2>', self.noop)

        handler, kw = router_instance.get_mapped_handle(request)
        self.assertEqual(kw, {'tag': '1234', 'tag2': '12323'})
        self.assertEqual(handler, self.noop)

        request2 = request_class(url='/1234/12323/123')
        router_instance.set_url('/<tag>/<tag2>/<b4>', self.noop)
        handler, kw = router_instance.get_mapped_handle(request2)
        self.assertEqual(kw, {'tag': '1234', 'tag2': '12323', 'b4': '123'})
        self.assertEqual(handler, self.noop)
Ejemplo n.º 5
0
    def test_oneArg(self):

        request = request_class(url='/1234')
        router_instance = Router()
        router_instance.set_url('/<tag>', self.noop)

        handler, kw = router_instance.get_mapped_handle(request)
        self.assertEqual(kw, {'tag': '1234'})
        self.assertEqual(handler, self.noop)
Ejemplo n.º 6
0
    def test_static_url(self):

        request = request_class(url='/1234')
        router_instance = Router()
        router_instance.set_url('/1234', self.noop)

        handler, kw = router_instance.get_mapped_handle(request)
        self.assertEqual(kw, {})
        self.assertEqual(handler, self.noop)
Ejemplo n.º 7
0
    def test_one_Blueprint(self):

        app = Luya()

        class Mv(MethodView):
            def __init__(self):
                pass

            def get(self, request):
                return response.html('<h1>class view test</h1>')

            def post(self, request):
                return response.html('<h1>post</h1>')

        app.add_route(Mv.to_view(), '/MethodView')

        request = request_class(url='/MethodView', method='GET')
        handler, kw = app.router.get_mapped_handle(request)
        self.assertEqual(kw, {})
        self.assertEqual(handler(request).status, 200)

        request = request_class(url='/MethodView', method='POST')
Ejemplo n.º 8
0
    def on_headers_complete(self):
        self.request = request_class(url_bytes=self.url,
                                     header=self.header,
                                     version=self.parser.get_http_version(),
                                     method=self.parser.get_method().decode())

        # here is where we deal with "Expect: 100-Continue"
        # when user upload some big file or big things
        # their client would send a header with 'Expect: 100-Continue'
        # to if check the server can be accepted.
        if self.has_stream:
            self.stream_handler, kw = self.app.router.get_mapped_handle(
                self.request)
            if self.stream_handler and kw['stream']:
                # here is a coroutine queue
                # when await get()
                self.request.stream = asyncio.Queue()
                self.execute_request_handler()
Ejemplo n.º 9
0
 def on_headers_complete(self):
     self.request = request_class(url=self.url.decode(),
                                  header=self.header,
                                  version=self.parser.get_http_version(),
                                  method=self.parser.get_method().decode())