예제 #1
0
 def test_static_match(self):
     route = Route(name='home', path='/')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
예제 #2
0
 def test_accept_method_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', REQUEST_METHOD='POST'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', REQUEST_METHOD='GET'))
     route = Route(name='test', path='/test', accepts=('POST',))
     assert route.match(valid_request)
     assert not route.match(invalid_request)
예제 #3
0
 def test_mandatory_segment_match(self):
     route = Route("search", path='/search/:keyword')
     invalid_request = create_request_from_environ(sample_environ(PATH_INFO='/searching'))
     valid_request_no_param = create_request_from_environ(sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request).matched
     assert not route.match(valid_request_no_param).matched
     assert route.match(valid_request_with_param).matched
예제 #4
0
 def test_subdomain_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test',
                        SERVER_NAME='clients.test.com'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', SERVER_NAME='clients2.test.com'))
     route = Route(name='test', path='/test', subdomain='clients')
     assert route.match(valid_request)
     assert not route.match(invalid_request)
예제 #5
0
 def test_optional_segment_with_defaults(self):
     route = Route(name="search", path='/search[/:keyword]', defaults={'keyword': 'blah'})
     invalid_request = create_request_from_environ(sample_environ(PATH_INFO='/searching'))
     valid_request = create_request_from_environ(sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(sample_environ(PATH_INFO='/search/test'))
     valid_request_with_default = route.match(valid_request)
     assert not route.match(invalid_request).matched
     assert valid_request_with_default.matched
     assert valid_request_with_default.params == {'keyword': 'blah'}
     assert route.match(valid_request_with_param).matched
예제 #6
0
 def test_optional_segment_match(self):
     route = Route(name="search", path='/search[/:keyword]')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/searching'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
     assert route.match(valid_request_with_param)
예제 #7
0
 def test_optional_segment_with_required(self):
     route = Route(
         name="search",
         path='/search[/:keyword]',
         requires={'keyword': 'blah'})
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search/blah'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
예제 #8
0
 def test_format_match(self):
     valid_request = create_request_from_environ(sample_environ(PATH_INFO='/dump', HTTP_ACCEPT='application/json'))
     invalid_request = create_request_from_environ(sample_environ(PATH_INFO='/dump', HTTP_ACCEPT='application/xml'))
     valid_request_segment = create_request_from_environ(sample_environ(PATH_INFO='/dump.json'))
     route = Route(name='json', path='/dump', requires={'format': 'json'})
     route_format = Route(name='json', path='/dump.:format', requires={'format': 'json'})
     assert route.match(valid_request).matched
     assert not route.match(invalid_request).matched
     assert route_format.match(valid_request_segment).matched
예제 #9
0
 def test_create_from_list(self):
     router = Router([
         {
             'name': 'home',
             'path': '/'
         }
     ])
     assert len(router) == 1
     router_objects = Router([
         Route(name='home', path='/')
     ])
     assert len(router_objects) == 1
예제 #10
0
 def test_create_from_dict(self):
     router = Router({
         'home': {
             'path': '/'
         }
     })
     assert len(router) == 1
     router_objects = Router({
         'home': Route(name='home', path='/')
     })
     assert len(router_objects) == 1
     for route in router:
         assert True
     assert router.assemble('home') == '/'
     assert repr(router) == '<watson.mvc.routing.Router routes:1>'
예제 #11
0
 def test_short_circuit(self):
     environ = sample_environ()
     route = Route('test',
                   path='/',
                   options={
                       'controller':
                       'tests.watson.mvc.support.ShortCircuitedController'
                   })
     match = RouteMatch(route, {
         'controller':
         'tests.watson.mvc.support.ShortCircuitedController'
     })
     event = Event('something',
                   params={
                       'route_match': match,
                       'container': IocContainer(),
                       'request': create_request_from_environ(environ)
                   })
     listener = listeners.DispatchExecute({'404': 'page/404'})
     response = listener(event)
     assert isinstance(response, Response)
예제 #12
0
 def test_create_route(self):
     route = Route(name='home', path='/')
     assert route.path == '/'
     assert route.name == 'home'
     assert repr(
         route) == '<watson.mvc.routing.Route name:home path:/ match:\/$>'
예제 #13
0
 def test_execute(self):
     route = Route('test', path='/')
     match = RouteMatch(route, {})
     event = Event('something', params={'route_match': match})
     listener = listeners.DispatchExecute({'404': 'page/404'})
     listener(event)
예제 #14
0
 def test_assemble_segment_route_missing_param(self):
     route = Route(name='test', path='/search/:keyword')
     route.assemble()
예제 #15
0
 def test_segment_bracket_mismatch(self):
     Route(name='mismatch', path='/search:keyword]')
예제 #16
0
 def test_assemble_static_route(self):
     route = Route(name='test', path='/testing')
     assert route.assemble() == '/testing'
예제 #17
0
 def test_assemble_segment_route(self):
     route = Route(name='test', path='/search[/:keyword]')
     assert route.assemble(keyword='test') == '/search/test'
예제 #18
0
 def test_assemble_segment_not_required(self):
     route = Route(name='test', path='/search[/:keyword]')
     assert route.assemble() == '/search'
     route2 = Route(name='test', path='/search[/:keyword]')
     assert route2.assemble(keyword='test') == '/search/test'
예제 #19
0
 def test_create_route_regex(self):
     route = Route(name='home', path='/', regex='.*')
     assert route.regex
예제 #20
0
 def test_assemble_segment_route_missing_param(self):
     route = Route(
         name='test',
         path='/search/:keyword',
         requires={'keyword': '.*'})
     route.assemble()