From df374057f7a42808d9482a8cac82111f24a104fa Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 31 Aug 2020 03:14:02 +0100 Subject: Tests: $host varaible test. Also added few tests for $uri and minor style fixes. --- test/test_variables.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'test/test_variables.py') diff --git a/test/test_variables.py b/test/test_variables.py index 805c5144..fb481be5 100644 --- a/test/test_variables.py +++ b/test/test_variables.py @@ -16,10 +16,11 @@ class TestVariables(TestApplicationProto): "GET": [{"action": {"return": 201}}], "POST": [{"action": {"return": 202}}], "3": [{"action": {"return": 203}}], - "4": [{"action": {"return": 204}}], + "4*": [{"action": {"return": 204}}], "blahGET}": [{"action": {"return": 205}}], "5GET": [{"action": {"return": 206}}], "GETGET": [{"action": {"return": 207}}], + "localhost": [{"action": {"return": 208}}], }, }, ), @@ -27,10 +28,7 @@ class TestVariables(TestApplicationProto): ) def conf_routes(self, routes): - self.assertIn( - 'success', - self.conf(routes, 'listeners/*:7080/pass') - ) + self.assertIn('success', self.conf(routes, 'listeners/*:7080/pass')) def test_variables_method(self): self.assertEqual(self.get()['status'], 201, 'method GET') @@ -40,7 +38,26 @@ class TestVariables(TestApplicationProto): self.conf_routes("\"routes$uri\"") self.assertEqual(self.get(url='/3')['status'], 203, 'uri') - self.assertEqual(self.get(url='/4')['status'], 204, 'uri 2') + self.assertEqual(self.get(url='/4*')['status'], 204, 'uri 2') + self.assertEqual(self.get(url='/4%2A')['status'], 204, 'uri 3') + + def test_variables_host(self): + self.conf_routes("\"routes/$host\"") + + def check_host(host, status=208): + self.assertEqual( + self.get(headers={'Host': host, 'Connection': 'close'})[ + 'status' + ], + status, + ) + + check_host('localhost') + check_host('localhost.') + check_host('localhost:7080') + check_host('.localhost', 404) + check_host('www.localhost', 404) + check_host('localhost1', 404) def test_variables_many(self): self.conf_routes("\"routes$uri$method\"") @@ -69,7 +86,7 @@ class TestVariables(TestApplicationProto): self.assertEqual(self.post()['status'], 202) self.conf_routes("\"routes${uri}\"") - self.assertEqual(self.get(url='/4')['status'], 204) + self.assertEqual(self.get(url='/4*')['status'], 204) self.conf_routes("\"routes/blah$method}\"") self.assertEqual(self.get()['status'], 205) -- cgit