def test_validate(self): route = Route('GET', '/test/<int:uderId>', lambda ignore: 'Test Done') route.compile() with Stub() as dispatcher: dispatcher.url = '/test/102' self.assertEqual(route.validate(dispatcher), route) with Stub() as dispatcher: dispatcher.url = '/test' self.assertEqual(route.validate(dispatcher), None)
def test_register_route_raise_route_error_on_invalid_HTTP_method(self): router = Router() ctl = StubController() route = Route('FAIL', '/defer', ctl.deferred) self.assertRaises(RouterError, router.register_route, ctl, route, ctl.deferred)
def test_register_route(self): router = Router() ctl = StubController() self.assertTrue(len(router.routes['GET']) == 0) route = Route('GET', '/defer', ctl.deferred) router.register_route(ctl, route, ctl.deferred) self.assertTrue(len(router.routes['GET']) == 1) self.assertTrue('/defer' in router.routes['GET']) self.assertTrue('StubController' in router.routes['GET']['/defer'])
def test_compile(self): route = Route('GET', '/test', lambda ignore: 'Test Done') route.compile() self.assertEqual(route.match.pattern, '^/test$') route.url = '/test/<int:userId>' route.compile() self.assertEqual(route.match.pattern, '^/test/(?P<userId>\\d+)$') route.url = '/test/<float:userId>' route.compile() self.assertEqual( route.match.pattern, '^/test/(?P<userId>\\d+.?\\d*)$' ) route.url = '/test/<userName>' route.compile() self.assertEqual(route.match.pattern, '^/test/(?P<userName>([^/]+))$')
def test_compile(self): route = Route('GET', '/test', lambda ignore: 'Test Done') route.compile() self.assertEqual(route.match.pattern, '^/test$') route.url = '/test/<int:userId>' route.compile() self.assertEqual(route.match.pattern, '^/test/(?P<userId>\\d+)$') route.url = '/test/<float:userId>' route.compile() self.assertEqual(route.match.pattern, '^/test/(?P<userId>\\d+.?\\d*)$') route.url = '/test/<userName>' route.compile() self.assertEqual(route.match.pattern, '^/test/(?P<userName>([^/]+))$')