Exemplo n.º 1
0
 def test_match_route(self):
     request = sample_request()
     router = routers.Dict({
         'home': {
             'path': '/'
         }
     })
     assert next(router.matches(request))
     assert router.match(request)
     assert not router.match(sample_request(PATH_INFO='/test'))
Exemplo n.º 2
0
 def test_optional_match(self):
     optional = routes.Segment(name='home', path='/about[/:company]')
     optional_nested = routes.Segment(name='home', path='/about[/:company[/:test]]')
     optional_required = routes.Segment(name='home', path='/about[/:company/:test]')
     request = support.sample_request(PATH_INFO='/about/test')
     request2 = support.sample_request(PATH_INFO='/about/test')
     request3 = support.sample_request(PATH_INFO='/about/test/blah')
     assert optional.match(request)
     assert len(optional.segments) == 2
     assert optional_nested.match(request2)
     assert optional_required.match(request3)
     assert not optional_required.match(request2)
Exemplo n.º 3
0
 def test_match_route(self):
     request = sample_request(PATH_INFO='/list')
     dict_router = routers.Dict({
         'dict': {
             'path': '/dict',
         }
     })
     list_router = routers.List([
         {'name': 'list', 'path': '/list'}
     ])
     router = routers.Choice(dict_router, list_router)
     match = router.match(request)
     assert match.route.name == 'list'
     assert len(router) == 2
     assert not router.match(sample_request(PATH_INFO='/test'))
Exemplo n.º 4
0
 def test_no_subdomain_match(self):
     route = routes.Literal(
         name='home', path='/', requires={'subdomain': 'test'})
     route2 = routes.Literal(
         name='home', path='/', requires={'subdomain': ('test',)})
     request = support.sample_request()
     assert not route.match(request)
     assert not route2.match(request)
Exemplo n.º 5
0
 def test_no_match_route(self):
     request = sample_request()
     router = routers.Dict({
         'home': {
             'path': '/about'
         }
     })
     with raises(StopIteration):
         next(router.matches(request))
Exemplo n.º 6
0
 def test_match_priority_similar_path(self):
     router = routers.Dict({
         'page1': {
             'path': '/page[/:id[/:blah]]',
         },
         'page2': {
             'path': '/page[/:id[/:blah[/:something]]]',
             'priority': 2
         }
     })
     request = sample_request(PATH_INFO='/page')
     match = router.match(request)
     assert match.route.name == 'page2'
Exemplo n.º 7
0
 def test_add_child_routes_complex(self):
     router = routers.Dict({
         '1st': {
             'path': '/home',
             'children': {
                 '2nd': {
                     'path': '/:test',
                     'requires': {'test': '\w+'},
                     'children': {
                         '3rd': {
                             'path': '/:tada'
                         }
                     }
                 }
             }
         }
     })
     request = sample_request(PATH_INFO='/home/blah')
     assert router.match(request).route.name == '1st/2nd'
     request = sample_request(PATH_INFO='/home/blah/tada')
     route_match = router.match(request)
     assert route_match.route.name == '1st/2nd/3rd'
     assert route_match.route.requires['test'] == '\w+'
     assert len(router) == 3
Exemplo n.º 8
0
 def test_get_match(self):
     request = support.sample_request(QUERY_STRING='test=blah')
     route = routes.LiteralRoute(
         name='home', path='/', requires={'test': '^blah'})
     assert route.match(request)
Exemplo n.º 9
0
 def test_match(self):
     route = routes.Segment(name='home', path='/:test')
     assert route.match(support.sample_request(PATH_INFO='/blah'))
Exemplo n.º 10
0
 def test_no_get_match(self):
     request = support.sample_request(QUERY_STRING='test=test')
     route = routes.Literal(
         name='home', path='/', requires={'test': 'blah'})
     match = route.match(request)
     assert not match
Exemplo n.º 11
0
 def test_no_match(self):
     route = routes.Segment(name='home', path='/:test', accepts=('GET',))
     assert not route.match(support.sample_request(PATH_INFO='/'))
     assert not route.match(
         support.sample_request(PATH_INFO='/test', REQUEST_METHOD='POST'))
Exemplo n.º 12
0
 def test_subdomain_match(self):
     request = support.sample_request(SERVER_NAME='clients2.test.com',
                                      HTTP_HOST='clients2.test.com')
     route = routes.Literal(
         name='home', path='/', requires={'subdomain': 'clients2'})
     assert route.match(request)
Exemplo n.º 13
0
 def test_no_format_match(self):
     route = routes.Literal(
         name='home', path='/', requires={'format': 'xml'})
     assert not route.match(support.sample_request(HTTP_ACCEPT='text/json'))
Exemplo n.º 14
0
 def test_match_regex(self):
     route = routes.Segment(name='wildcard', regex='^/.*')
     assert route.match(support.sample_request(PATH_INFO='/test'))
Exemplo n.º 15
0
 def test_accept_match(self):
     route = routes.Literal(name='home', path='/', accepts=('POST',))
     assert route.match(support.sample_request(REQUEST_METHOD='POST'))
Exemplo n.º 16
0
 def test_no_accept_match(self):
     route = routes.Literal(name='home', path='/', accepts=('POST',))
     assert not route.match(support.sample_request())
Exemplo n.º 17
0
 def test_match(self):
     route = routes.Literal(name='home', path='/')
     assert route.match(support.sample_request())
Exemplo n.º 18
0
 def test_optional_params(self):
     route = routes.Segment(name='home', path='/about[/:company]', defaults={'company': 'test'})
     request = support.sample_request(PATH_INFO='/about')
     assert route.match(request).params['company'] == 'test'