diff options
author | Max Romanov <max.romanov@nginx.com> | 2020-11-10 22:27:08 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2020-11-10 22:27:08 +0300 |
commit | 5fd2933d2e54a7b5781698a670abf89b1031db44 (patch) | |
tree | 7d682ba1785ac883760331b4d123b0c17eaed10e /test | |
parent | 4ca9ba34081c44f5d421b171ffaf874fb341d73f (diff) | |
download | unit-5fd2933d2e54a7b5781698a670abf89b1031db44.tar.gz unit-5fd2933d2e54a7b5781698a670abf89b1031db44.tar.bz2 |
Python: supporting ASGI legacy protocol.
Introducing manual protocol selection for 'universal' apps and frameworks.
Diffstat (limited to '')
-rw-r--r-- | test/python/legacy/asgi.py | 13 | ||||
-rw-r--r-- | test/python/legacy_force/asgi.py | 17 | ||||
-rw-r--r-- | test/test_asgi_application.py | 26 | ||||
-rw-r--r-- | test/unit/applications/lang/python.py | 3 |
4 files changed, 58 insertions, 1 deletions
diff --git a/test/python/legacy/asgi.py b/test/python/legacy/asgi.py new file mode 100644 index 00000000..f065d026 --- /dev/null +++ b/test/python/legacy/asgi.py @@ -0,0 +1,13 @@ +def application(scope): + assert scope['type'] == 'http' + + return app_http + +async def app_http(receive, send): + await send({ + 'type': 'http.response.start', + 'status': 200, + 'headers': [ + (b'content-length', b'0'), + ] + }) diff --git a/test/python/legacy_force/asgi.py b/test/python/legacy_force/asgi.py new file mode 100644 index 00000000..2e5859f2 --- /dev/null +++ b/test/python/legacy_force/asgi.py @@ -0,0 +1,17 @@ +def application(scope, receive=None, send=None): + assert scope['type'] == 'http' + + if receive == None and send == None: + return app_http + + else: + return app_http(receive, send) + +async def app_http(receive, send): + await send({ + 'type': 'http.response.start', + 'status': 200, + 'headers': [ + (b'content-length', b'0'), + ] + }) diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index 2e73e529..e90d78bc 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -418,3 +418,29 @@ Connection: close sock.close() assert len(socks) == len(threads), 'threads differs' + + def test_asgi_application_legacy(self): + self.load('legacy') + + resp = self.get( + headers={ + 'Host': 'localhost', + 'Content-Length': '0', + 'Connection': 'close', + }, + ) + + assert resp['status'] == 200, 'status' + + def test_asgi_application_legacy_force(self): + self.load('legacy_force', protocol='asgi') + + resp = self.get( + headers={ + 'Host': 'localhost', + 'Content-Length': '0', + 'Connection': 'close', + }, + ) + + assert resp['status'] == 200, 'status' diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 20d4f257..792a86fa 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -42,7 +42,8 @@ class TestApplicationPython(TestApplicationProto): "module": module, } - for attr in ('callable', 'home', 'limits', 'path', 'threads'): + for attr in ('callable', 'home', 'limits', 'path', 'protocol', + 'threads'): if attr in kwargs: app[attr] = kwargs.pop(attr) |