summaryrefslogtreecommitdiffhomepage
path: root/test/test_routing.py
diff options
context:
space:
mode:
authorAxel Duch <axel.duch@nginx.com>2020-07-04 03:24:07 +0100
committerAxel Duch <axel.duch@nginx.com>2020-07-04 03:24:07 +0100
commita9a21f6fe41f4da4c1dcf2d9b35287d67b1fa4d1 (patch)
treedec31a1e0b38f64fb266349fce4f2210394de4d9 /test/test_routing.py
parent9bd6baefaee3a3e9b8dfe6427404512c9a66c969 (diff)
downloadunit-a9a21f6fe41f4da4c1dcf2d9b35287d67b1fa4d1.tar.gz
unit-a9a21f6fe41f4da4c1dcf2d9b35287d67b1fa4d1.tar.bz2
Router: route patterns multi wildcards support.
Diffstat (limited to 'test/test_routing.py')
-rw-r--r--test/test_routing.py49
1 files changed, 44 insertions, 5 deletions
diff --git a/test/test_routing.py b/test/test_routing.py
index 3cf4009c..8a196e88 100644
--- a/test/test_routing.py
+++ b/test/test_routing.py
@@ -115,10 +115,41 @@ class TestRouting(TestApplicationProto):
def test_routes_match_invalid(self):
self.route_match_invalid({"method": "**"})
- self.route_match_invalid({"method": "blah**"})
- self.route_match_invalid({"host": "*blah*blah"})
- self.route_match_invalid({"host": "blah*blah*blah"})
- self.route_match_invalid({"host": "blah*blah*"})
+
+ def test_routes_match_valid(self):
+ self.route_match({"method": "blah*"})
+ self.route_match({"host": "*blah*blah"})
+ self.route_match({"host": "blah*blah*blah"})
+ self.route_match({"host": "blah*blah*"})
+
+ def test_routes_match_empty_exact(self):
+ self.route_match({"uri": ""})
+ self.assertEqual(self.get()['status'], 404)
+
+ self.route_match({"uri": "/"})
+ self.assertEqual(self.get()['status'], 200)
+ self.assertEqual(self.get(url='/blah')['status'], 404)
+
+ def test_routes_match_negative(self):
+ self.route_match({"uri": "!"})
+ self.assertEqual(self.get()['status'], 404)
+
+ self.route_match({"uri": "!/"})
+ self.assertEqual(self.get()['status'], 404)
+ self.assertEqual(self.get(url='/blah')['status'], 200)
+
+ self.route_match({"uri": "!*blah"})
+ self.assertEqual(self.get()['status'], 200)
+ self.assertEqual(self.get(url='/bla')['status'], 200)
+ self.assertEqual(self.get(url='/blah')['status'], 404)
+ self.assertEqual(self.get(url='/blah1')['status'], 200)
+
+ self.route_match({"uri": "!/blah*1*"})
+ self.assertEqual(self.get()['status'], 200)
+ self.assertEqual(self.get(url='/blah')['status'], 200)
+ self.assertEqual(self.get(url='/blah1')['status'], 404)
+ self.assertEqual(self.get(url='/blah12')['status'], 404)
+ self.assertEqual(self.get(url='/blah2')['status'], 200)
def test_routes_match_wildcard_middle(self):
self.route_match({"host": "ex*le"})
@@ -181,6 +212,15 @@ class TestRouting(TestApplicationProto):
self.assertEqual(self.get(url='/blah')['status'], 200, '/blah')
self.assertEqual(self.get(url='/BLAH')['status'], 404, '/BLAH')
+ def test_routes_match_many_wildcard_substrings_case_sensitive(self):
+ self.route_match({"uri": "*a*B*c*"})
+
+ self.assertEqual(self.get(url='/blah-a-B-c-blah')['status'], 200)
+ self.assertEqual(self.get(url='/a-B-c')['status'], 200)
+ self.assertEqual(self.get(url='/aBc')['status'], 200)
+ self.assertEqual(self.get(url='/aBCaBbc')['status'], 200)
+ self.assertEqual(self.get(url='/ABc')['status'], 404)
+
def test_routes_pass_encode(self):
def check_pass(path, name):
self.assertIn(
@@ -1362,7 +1402,6 @@ class TestRouting(TestApplicationProto):
self.route_match_invalid({"arguments": ["var"]})
self.route_match_invalid({"arguments": [{"var1": {}}]})
self.route_match_invalid({"arguments": {"": "bar"}})
- self.route_match_invalid({"arguments": {"foo": "*ba*r"}})
self.route_match_invalid({"arguments": {"foo": "%"}})
self.route_match_invalid({"arguments": {"foo": "%1G"}})
self.route_match_invalid({"arguments": {"%": "bar"}})