예제 #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_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
예제 #6
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
예제 #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_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)