コード例 #1
0
 def test_parser_raise_exception_for_empty_optional_part(self):
     try:
         parser = RouteParser()
         route = '/test[]'
         parser.parse(route)
     except BadRouteException as error:
         self.assertEqual(error.message, "Empty optional part")
コード例 #2
0
 def test_parser_raise_exception_for_single_optional_part_nested_inside_empty_optional(
         self):
     try:
         parser = RouteParser()
         route = '[[test]]'
         parser.parse(route)
     except BadRouteException as error:
         self.assertEqual(error.message, "Empty optional part")
コード例 #3
0
 def test_parser_raise_exception_for_optional_part_at_the_mid_route(self):
     try:
         parser = RouteParser()
         route = '/test[/opt]/required'
         parser.parse(route)
     except BadRouteException as error:
         self.assertEqual(
             error.message,
             "Optional segments can only occur at the end of a route")
コード例 #4
0
 def test_parser_raise_exception_for_unclosing_start_optional(self):
     try:
         parser = RouteParser()
         route = '/testopt]'
         parser.parse(route)
     except BadRouteException as error:
         self.assertEqual(
             error.message,
             "Number of opening '[' and closing ']' does not match")
コード例 #5
0
 def test_parser_for_route_with_optional_end_path(self):
     parser = RouteParser()
     route = '/test[opt]'
     self.assertEqual(parser.parse(route), [
         ['/test'],
         ['/testopt'],
     ])
コード例 #6
0
 def test_parser_for_route_with_placeholder(self):
     parser = RouteParser()
     route = r"/articles/{id:\d+}[/{title}]"
     self.assertEqual(
         parser.parse(route),
         [['/articles/', ['id', '\\d+']],
          ['/articles/', ['id', '\\d+'], '/', ['title', '[^/]+']]])
コード例 #7
0
 def test_parser_for_route_with_single_optional_path(self):
     parser = RouteParser()
     route = '[test]'
     self.assertEqual(parser.parse(route), [
         [''],
         ['test'],
     ])
コード例 #8
0
 def test_parser_for_route_with_optional_end_path_and_placheholder_inside(
         self):
     parser = RouteParser()
     route = '/test[/{param}]'
     self.assertEqual(parser.parse(route), [
         ['/test'],
         ['/test/', ['param', '[^/]+']],
     ])
コード例 #9
0
 def test_parser_for_route_with_placeholder_at_start_and_optional_path_at_end(
         self):
     parser = RouteParser()
     route = '/test[/{name}[/{id:[0-9]+}]]'
     self.assertEqual(parser.parse(route), [
         ['/test'],
         ['/test/', ['name', '[^/]+']],
         ['/test/', ['name', '[^/]+'], '/', ['id', '[0-9]+']],
     ])
コード例 #10
0
 def test_parser_for_route_without_placeholder(self):
     parser = RouteParser()
     route = r"/articles/"
     self.assertEqual(parser.parse(route), [
         ['/articles/'],
     ])
コード例 #11
0
 def test_parser_for_route_with_complex_regex_params(self):
     parser = RouteParser()
     route = r'/test/{ param : \d{1,9} }'
     self.assertEqual(parser.parse(route), [
         ['/test/', ['param', r'\d{1,9}']],
     ])
コード例 #12
0
 def test_parser_for_route_with_multiple_placeholder(self):
     parser = RouteParser()
     route = '/test/{param1}/test2/{param2}'
     self.assertEqual(parser.parse(route), [
         ['/test/', ['param1', '[^/]+'], '/test2/', ['param2', '[^/]+']],
     ])
コード例 #13
0
 def test_parser_for_route_with_complex_single_placeholder(self):
     parser = RouteParser()
     route = '/{_foo:.*}'
     self.assertEqual(parser.parse(route), [
         ['/', ['_foo', '.*']],
     ])
コード例 #14
0
 def test_parser_for_route_with_placeholer_param_as_path_segment(self):
     parser = RouteParser()
     route = '/test/{param}'
     self.assertEqual(parser.parse(route), [
         ['/test/', ['param', '[^/]+']],
     ])
コード例 #15
0
 def test_parser_for__basic_route(self):
     parser = RouteParser()
     route = '/test'
     self.assertEqual(parser.parse(route), [
         ['/test'],
     ])
コード例 #16
0
 def test_parser_for_route_with_empty_route(self):
     parser = RouteParser()
     route = ''
     self.assertEqual(parser.parse(route), [
         [''],
     ])
コード例 #17
0
 def test_parser_for_route_with_placeholder_in_middle_of_path_segment(self):
     parser = RouteParser()
     route = '/te{ param }st'
     self.assertEqual(parser.parse(route), [
         ['/te', ['param', '[^/]+'], 'st'],
     ])
コード例 #18
0
 def test_parser_for_route_with_single_placeholder(self):
     parser = RouteParser()
     route = '/{foo-bar}'
     self.assertEqual(parser.parse(route), [
         ['/', ['foo-bar', '[^/]+']],
     ])