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)
def test_re_route(self): self.rs.route(URLTarget('/a/?'), self.cb) self.assertRaises(RouteTaken, self.rs.route, URLTarget('/a/'), self.cb, catchall=True)
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)
def test_truth_has_route(self): self.rs.route(URLTarget('/a/b/c/d'), mock.Mock()) self.assertTrue(self.rs)
def test_route_static(self): self.rs.route(URLTarget('/a/b'), self.cb) self.assertEqual(self.rs.resolve(URLTarget('/a/b')), ResolvedRequest(self.cb, []))
def test_contains(self): self.rs.route(URLTarget('/a/'), self.cb, catchall=True) self.assertTrue(URLTarget('/a/') in self.rs)
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)
def test_contains_4(self): self.assertTrue(URLTarget('/c/?/d') in self.rs)
def test_remaining(self): target = URLTarget('/dest/in/ation') self.assertEqual(target.remaining, 'dest/in/ation') next(target) self.assertEqual(target.remaining, 'in/ation')
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']))
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)
def test_add_argument(self): target = URLTarget('/dest/in/ation') target.add_argument('in') self.assertEqual(target.arguments, ['in'])
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']))
def test_not_contains_5(self): self.assertFalse(URLTarget('/d/') in self.rs)
def test_not_contains_3(self): self.assertFalse(URLTarget('/c/?') in self.rs)
def test_not_contains_2(self): self.assertFalse(URLTarget('/a/c') in self.rs)
def test_route_dynamic(self): self.rs.route(URLTarget('/a/?'), self.cb) self.assertEqual(self.rs.resolve(URLTarget('/a/b')), ResolvedRequest(self.cb, ['b']))
def test_resolve_slash(self): self.rs.route(URLTarget('/a/'), self.cb) self.assertEqual(self.rs.resolve(URLTarget('/a/')), ResolvedRequest(self.cb, []))
def test_re_route_dynamic(self): self.rs.route(URLTarget('/a/?'), self.cb) self.assertRaises(RouteTaken, self.rs.route, URLTarget('/a/?'), self.cb)
def test_nonzero(self): target = URLTarget('/') self.assertTrue(bool(target)) next(target) self.assertFalse(bool(target))
def test_resolve_no_route_under(self): self.assertEqual(self.rs.resolve(URLTarget('/a/c')), None)
def test_contains_3(self): self.assertTrue(URLTarget('/a/?') in self.rs)
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)