summaryrefslogtreecommitdiffhomepage
path: root/test/test_asgi_targets.py
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2022-12-15 08:17:39 -0800
committerKonstantin Pavlov <thresh@nginx.com>2022-12-15 08:17:39 -0800
commite22669f2728814aba82da14702d18bfa9685311e (patch)
treec9c9471dab359e8e33fca24c5d4f035ab5b278db /test/test_asgi_targets.py
parenta1d28488f9df8e28ee25ea438c275b96b9afe5b6 (diff)
parent4409a10ff0bd6bb45fb88716bd383cd867958a8a (diff)
downloadunit-e22669f2728814aba82da14702d18bfa9685311e.tar.gz
unit-e22669f2728814aba82da14702d18bfa9685311e.tar.bz2
Merged with the default branch.
Diffstat (limited to 'test/test_asgi_targets.py')
-rw-r--r--test/test_asgi_targets.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/test_asgi_targets.py b/test/test_asgi_targets.py
index c1e345ef..84d7b3b0 100644
--- a/test/test_asgi_targets.py
+++ b/test/test_asgi_targets.py
@@ -90,3 +90,48 @@ class TestASGITargets(TestApplicationPython):
)
assert self.get(url='/1')['status'] != 200
+
+ def test_asgi_targets_prefix(self):
+ self.conf_targets(
+ {
+ "1": {
+ "module": "asgi",
+ "callable": "application_prefix",
+ "prefix": "/1/",
+ },
+ "2": {
+ "module": "asgi",
+ "callable": "application_prefix",
+ "prefix": "/api",
+ },
+ }
+ )
+ self.conf(
+ [
+ {
+ "match": {"uri": "/1*"},
+ "action": {"pass": "applications/targets/1"},
+ },
+ {
+ "match": {"uri": "*"},
+ "action": {"pass": "applications/targets/2"},
+ },
+ ],
+ "routes",
+ )
+
+ def check_prefix(url, prefix):
+ resp = self.get(url=url)
+ assert resp['status'] == 200
+ assert resp['headers']['prefix'] == prefix
+
+ check_prefix('/1', '/1')
+ check_prefix('/11', 'NULL')
+ check_prefix('/1/', '/1')
+ check_prefix('/', 'NULL')
+ check_prefix('/ap', 'NULL')
+ check_prefix('/api', '/api')
+ check_prefix('/api/', '/api')
+ check_prefix('/api/test/', '/api')
+ check_prefix('/apis', 'NULL')
+ check_prefix('/apis/', 'NULL')