summaryrefslogtreecommitdiffhomepage
path: root/test/test_asgi_targets.py
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2021-05-27 17:03:24 +0300
committerAndrei Belov <defan@nginx.com>2021-05-27 17:03:24 +0300
commit0afb4b5790c5a37ba6b880eb351a65fe00521fbe (patch)
treec7e0b6bed92ee62a5e8b13c945c4134e68554cec /test/test_asgi_targets.py
parent21ff5e086ece7188df3b7338d228fa4fb7f886af (diff)
parentd06e55dfa3692e27a92ff6c2534bb083416bc0c8 (diff)
downloadunit-1.24.0-1.tar.gz
unit-1.24.0-1.tar.bz2
Merged with the default branch.1.24.0-1
Diffstat (limited to 'test/test_asgi_targets.py')
-rw-r--r--test/test_asgi_targets.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/test_asgi_targets.py b/test/test_asgi_targets.py
new file mode 100644
index 00000000..a0eb1f84
--- /dev/null
+++ b/test/test_asgi_targets.py
@@ -0,0 +1,92 @@
+from distutils.version import LooseVersion
+
+import pytest
+
+from unit.applications.lang.python import TestApplicationPython
+from unit.option import option
+
+
+class TestASGITargets(TestApplicationPython):
+ prerequisites = {
+ 'modules': {'python': lambda v: LooseVersion(v) >= LooseVersion('3.5')}
+ }
+ load_module = 'asgi'
+
+ @pytest.fixture(autouse=True)
+ def setup_method_fixture(self):
+ assert 'success' in self.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes"}},
+ "routes": [
+ {
+ "match": {"uri": "/1"},
+ "action": {"pass": "applications/targets/1"},
+ },
+ {
+ "match": {"uri": "/2"},
+ "action": {"pass": "applications/targets/2"},
+ },
+ ],
+ "applications": {
+ "targets": {
+ "type": "python",
+ "processes": {"spare": 0},
+ "working_directory": option.test_dir
+ + "/python/targets/",
+ "path": option.test_dir + '/python/targets/',
+ "protocol": "asgi",
+ "targets": {
+ "1": {
+ "module": "asgi",
+ "callable": "application_200",
+ },
+ "2": {
+ "module": "asgi",
+ "callable": "application_201",
+ },
+ },
+ }
+ },
+ }
+ )
+
+ def conf_targets(self, targets):
+ assert 'success' in self.conf(targets, 'applications/targets/targets')
+
+ def test_asgi_targets(self):
+ assert self.get(url='/1')['status'] == 200
+ assert self.get(url='/2')['status'] == 201
+
+ def test_asgi_targets_legacy(self):
+ self.conf_targets(
+ {
+ "1": {"module": "asgi", "callable": "legacy_application_200"},
+ "2": {"module": "asgi", "callable": "legacy_application_201"},
+ }
+ )
+
+ assert self.get(url='/1')['status'] == 200
+ assert self.get(url='/2')['status'] == 201
+
+ def test_asgi_targets_mix(self):
+ self.conf_targets(
+ {
+ "1": {"module": "asgi", "callable": "application_200"},
+ "2": {"module": "asgi", "callable": "legacy_application_201"},
+ }
+ )
+
+ assert self.get(url='/1')['status'] == 200
+ assert self.get(url='/2')['status'] == 201
+
+ def test_asgi_targets_broken(self, skip_alert):
+ skip_alert(r'Python failed to get "blah" from module')
+
+ self.conf_targets(
+ {
+ "1": {"module": "asgi", "callable": "application_200"},
+ "2": {"module": "asgi", "callable": "blah"},
+ }
+ )
+
+ assert self.get(url='/1')['status'] != 200