comparison roundup/web/router.py @ 4910:e5f90a69f660 routing

routing: Fix router test
author anatoly techtonik <techtonik@gmail.com>
date Wed, 16 Jul 2014 03:22:05 +0300
parents f31c93abedf6
children 35dc9191394d
comparison
equal deleted inserted replaced
4909:f31c93abedf6 4910:e5f90a69f660
23 ExampleFileHandler = NamedObject('ExampleFileHandler') 23 ExampleFileHandler = NamedObject('ExampleFileHandler')
24 24
25 25
26 EXAMPLE_URLMAP = ( 26 EXAMPLE_URLMAP = (
27 'static/(.*)', ExampleFileHandler, 27 'static/(.*)', ExampleFileHandler,
28 '', ExampleHandler 28 'index', ExampleHandler
29 ) 29 )
30 30
31 31
32 # --- Regexp based router 32 # --- Regexp based router
33 33
49 """ 49 """
50 # strip leading slashes before matching 50 # strip leading slashes before matching
51 path = urlpath.lstrip('/') 51 path = urlpath.lstrip('/')
52 for i in range(0, len(self.urlmap), 2): 52 for i in range(0, len(self.urlmap), 2):
53 pattern, handler = self.urlmap[i], self.urlmap[i+1] 53 pattern, handler = self.urlmap[i], self.urlmap[i+1]
54 match = re.match(pattern, urlpath) 54 match = re.match(pattern, path)
55 if match: 55 if match:
56 return handler, match.groups() 56 return handler, match.groups()
57 return (None, ()) 57 return (None, ())
58 58
59 59
66 import unittest 66 import unittest
67 class test_Router(unittest.TestCase): 67 class test_Router(unittest.TestCase):
68 def test_example_routes(self): 68 def test_example_routes(self):
69 router = Router(EXAMPLE_URLMAP) 69 router = Router(EXAMPLE_URLMAP)
70 self.assertEquals(router.get_handler(''), (None, ())) 70 self.assertEquals(router.get_handler(''), (None, ()))
71 handler, params = router.get_handler('/') 71 handler, params = router.get_handler('/index')
72 self.assertEquals(handler, ExampleHandler) 72 self.assertEquals(handler, ExampleHandler)
73 self.assertEquals(params, tuple()) 73 self.assertEquals(params, tuple())
74 74
75 unittest.main() 75 unittest.main()

Roundup Issue Tracker: http://roundup-tracker.org/