예제 #1
0
 def setUp(self):
     self.rs = rs = RouterStep()
     cb = mock.Mock()
     rs.route(URLTarget('/a/'), cb)
     rs.route(URLTarget('/a/b'), cb)
     rs.route(URLTarget('/a/?'), cb)
     rs.route(URLTarget('/c/?/d'), cb)
예제 #2
0
 def test_re_route(self):
     self.rs.route(URLTarget('/a/?'), self.cb)
     self.assertRaises(RouteTaken,
                       self.rs.route,
                       URLTarget('/a/'),
                       self.cb,
                       catchall=True)
예제 #3
0
    def test_unroute(self):
        self.rs.route(URLTarget('/a/'), self.cb)
        self.rs.route(URLTarget('/a/b'), self.cb)

        self.rs.unroute(URLTarget('/a/'))
        self.assertTrue(self.rs.resolve(URLTarget('/a/')) is None)
        self.assertFalse(self.rs.resolve(URLTarget('/a/b')) is None)
예제 #4
0
 def test_truth_has_route(self):
     self.rs.route(URLTarget('/a/b/c/d'), mock.Mock())
     self.assertTrue(self.rs)
예제 #5
0
 def test_route_static(self):
     self.rs.route(URLTarget('/a/b'), self.cb)
     self.assertEqual(self.rs.resolve(URLTarget('/a/b')),
                      ResolvedRequest(self.cb, []))
예제 #6
0
 def test_contains(self):
     self.rs.route(URLTarget('/a/'), self.cb, catchall=True)
     self.assertTrue(URLTarget('/a/') in self.rs)
예제 #7
0
 def test_not_contains(self):
     self.rs.route(URLTarget('/a/'), self.cb, catchall=True)
     self.assertFalse(URLTarget('/a/d') in self.rs)
     self.assertFalse(URLTarget('/a/?/d') in self.rs)
     self.assertFalse(URLTarget('/a/?') in self.rs)
예제 #8
0
 def test_contains_4(self):
     self.assertTrue(URLTarget('/c/?/d') in self.rs)
예제 #9
0
 def test_remaining(self):
     target = URLTarget('/dest/in/ation')
     self.assertEqual(target.remaining, 'dest/in/ation')
     next(target)
     self.assertEqual(target.remaining, 'in/ation')
예제 #10
0
 def test_route_dynamic_path(self):
     self.rs.route(URLTarget('/a/?/'), self.cb, catchall=True)
     self.assertEqual(self.rs.resolve(URLTarget('/a/b/c/d')),
                      ResolvedRequest(self.cb, ['b', 'c/d']))
예제 #11
0
 def test_resolve_no_route_intermediate(self):
     self.rs.route(URLTarget('/a/b/c'), self.cb)
     self.assertEqual(self.rs.resolve(URLTarget('/a/b')), None)
예제 #12
0
 def test_add_argument(self):
     target = URLTarget('/dest/in/ation')
     target.add_argument('in')
     self.assertEqual(target.arguments, ['in'])
예제 #13
0
 def test_route_path(self):
     self.rs.route(URLTarget('/a/'), self.cb, catchall=True)
     self.assertEqual(self.rs.resolve(URLTarget('/a/b/c')),
                      ResolvedRequest(self.cb, ['b/c']))
예제 #14
0
 def test_not_contains_5(self):
     self.assertFalse(URLTarget('/d/') in self.rs)
예제 #15
0
 def test_not_contains_3(self):
     self.assertFalse(URLTarget('/c/?') in self.rs)
예제 #16
0
 def test_not_contains_2(self):
     self.assertFalse(URLTarget('/a/c') in self.rs)
예제 #17
0
 def test_route_dynamic(self):
     self.rs.route(URLTarget('/a/?'), self.cb)
     self.assertEqual(self.rs.resolve(URLTarget('/a/b')),
                      ResolvedRequest(self.cb, ['b']))
예제 #18
0
 def test_resolve_slash(self):
     self.rs.route(URLTarget('/a/'), self.cb)
     self.assertEqual(self.rs.resolve(URLTarget('/a/')),
                      ResolvedRequest(self.cb, []))
예제 #19
0
 def test_re_route_dynamic(self):
     self.rs.route(URLTarget('/a/?'), self.cb)
     self.assertRaises(RouteTaken, self.rs.route, URLTarget('/a/?'),
                       self.cb)
예제 #20
0
 def test_nonzero(self):
     target = URLTarget('/')
     self.assertTrue(bool(target))
     next(target)
     self.assertFalse(bool(target))
예제 #21
0
 def test_resolve_no_route_under(self):
     self.assertEqual(self.rs.resolve(URLTarget('/a/c')), None)
예제 #22
0
 def test_contains_3(self):
     self.assertTrue(URLTarget('/a/?') in self.rs)
예제 #23
0
 def test_unroute_inside(self):
     self.rs.route(URLTarget('/a/'), self.cb, catchall=True)
     self.rs.unroute(URLTarget('/a/?/c'))
     self.assertFalse(self.rs.resolve(URLTarget('/a/b/c')) is None)
예제 #24
0
 def test_add_argument(self):
     target = URLTarget('/dest/in/ation')
     target.add_argument('in')
     self.assertEqual(target.arguments, ['in'])