Exemple #1
0
 def test_params(self):
     t = build_route_tree(
         [("GET", "/one", 1), ("GET", "/<p1>", 2), ("GET", "/<p1>/three", 3), ("GET", "/<p1>/<p2>", 2)]
     )
     self.assertEqual(t.route("GET", "/one"), (1, {}))
     self.assertEqual(t.route("GET", "/two"), (2, {"p1": "two"}))
     self.assertEqual(t.route("GET", "/two/three"), (3, {"p1": "two"}))
     self.assertEqual(t.route("GET", "/two/foo"), (2, {"p1": "two", "p2": "foo"}))
Exemple #2
0
 def test_simple(self):
     t = build_route_tree([("GET", "/", 0), ("GET", "/one", 1), ("POST", "/two/three", 2)])
     self.assertEqual(t.route("GET", "/"), (0, {}))
     self.assertEqual(t.route("GET", "/one"), (1, {}))
     self.assertEqual(t.route("POST", "/two/three"), (2, {}))
     with self.assertRaises(exceptions.HTTPException):
         t.route("POST", "/two")
     with self.assertRaises(exceptions.HTTPException):
         t.route("GET", "/two/three")
Exemple #3
0
 def test_conflict(self):
     with self.assertRaises(exceptions.RouteConflict):
         build_route_tree([("GET", "/<p1>", 1), ("GET", "/<p2>", 2)])
     with self.assertRaises(exceptions.RouteConflict):
         build_route_tree([("GET", "/one/", 1), ("GET", "/one/", 2)])
     with self.assertRaises(Exception):
         build_route_tree([("GET", "/<p1>//", 1)])
Exemple #4
0
	def test_simple(self):
		t = build_route_tree([
			('GET', '/', 0),
			('GET', '/one', 1),
			('POST', '/two/three', 2),
		])
		self.assertEqual(t.route('GET', '/'), (0, {}))
		self.assertEqual(t.route('GET', '/one'), (1, {}))
		self.assertEqual(t.route('POST', '/two/three'), (2, {}))
		with self.assertRaises(exceptions.HTTPException):
			t.route('POST', '/two')
		with self.assertRaises(exceptions.HTTPException):
			t.route('GET', '/two/three')
Exemple #5
0
	def test_params(self):
		t = build_route_tree([
			('GET', '/one', 1),
			('GET', '/<p1>', 2),
			('GET', '/<p1>/three', 3),
			('GET', '/<p1>/three/four', 4),
			('GET', '/<p1>/<path:p2>', 2),
		])
		self.assertEqual(t.route('GET', '/one'), (1, {}))
		self.assertEqual(t.route('GET', '/two'), (2, {'p1': 'two'}))
		self.assertEqual(t.route('GET', '/two/three'), (3, {'p1': 'two'}))
		self.assertEqual(t.route('GET', '/two/three/four'), (4, {'p1': 'two'}))
		self.assertEqual(t.route('GET', '/two/foo'), (2, {'p1': 'two', 'p2': 'foo'}))
		self.assertEqual(t.route('GET', '/two/foo/bar'), (2, {'p1': 'two', 'p2': 'foo/bar'}))
Exemple #6
0
	def test_conflict(self):
		with self.assertRaises(exceptions.RouteConflict):
			build_route_tree([
				('GET', '/<p1>', 1),
				('GET', '/<p2>', 2),
			])
		with self.assertRaises(exceptions.RouteConflict):
			build_route_tree([
				('GET', '/one/', 1),
				('GET', '/one/', 2),
			])
		with self.assertRaises(Exception):
			build_route_tree([
				('GET', '/<p1>//', 1),
			])