Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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'])
Exemple #4
0
    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)
Exemple #5
0
 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>([^/]+))$')
Exemple #6
0
 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>([^/]+))$')