summaryrefslogtreecommitdiffhomepage
path: root/test/python
diff options
context:
space:
mode:
authorOisin Canty <o.canty@f5.com>2021-05-20 13:03:12 +0000
committerOisin Canty <o.canty@f5.com>2021-05-20 13:03:12 +0000
commite50bb120e2a2dfad55d28724133656264ef13dc8 (patch)
tree53a115359a9ad7d1f60f5dadb6f88a431a9eb563 /test/python
parentf60389a782470e31dc555ab864784b536f2544ca (diff)
downloadunit-e50bb120e2a2dfad55d28724133656264ef13dc8.tar.gz
unit-e50bb120e2a2dfad55d28724133656264ef13dc8.tar.bz2
Tests: Python targets.
Diffstat (limited to 'test/python')
-rw-r--r--test/python/lifespan/empty/asgi.py16
-rw-r--r--test/python/targets/asgi.py54
-rw-r--r--test/python/targets/wsgi.py8
3 files changed, 74 insertions, 4 deletions
diff --git a/test/python/lifespan/empty/asgi.py b/test/python/lifespan/empty/asgi.py
index ea43af13..8ceecc2f 100644
--- a/test/python/lifespan/empty/asgi.py
+++ b/test/python/lifespan/empty/asgi.py
@@ -1,19 +1,19 @@
import os
-async def application(scope, receive, send):
+async def handler(prefix, scope, receive, send):
if scope['type'] == 'lifespan':
- with open('version', 'w+') as f:
+ with open(prefix + 'version', 'w+') as f:
f.write(
scope['asgi']['version'] + ' ' + scope['asgi']['spec_version']
)
while True:
message = await receive()
if message['type'] == 'lifespan.startup':
- os.remove('startup')
+ os.remove(prefix + 'startup')
await send({'type': 'lifespan.startup.complete'})
elif message['type'] == 'lifespan.shutdown':
- os.remove('shutdown')
+ os.remove(prefix + 'shutdown')
await send({'type': 'lifespan.shutdown.complete'})
return
@@ -25,3 +25,11 @@ async def application(scope, receive, send):
'headers': [(b'content-length', b'0'),],
}
)
+
+
+async def application(scope, receive, send):
+ return await handler('', scope, receive, send)
+
+
+async def application2(scope, receive, send):
+ return await handler('app2_', scope, receive, send)
diff --git a/test/python/targets/asgi.py b/test/python/targets/asgi.py
new file mode 100644
index 00000000..b51f3964
--- /dev/null
+++ b/test/python/targets/asgi.py
@@ -0,0 +1,54 @@
+async def application_201(scope, receive, send):
+ assert scope['type'] == 'http'
+
+ await send(
+ {
+ 'type': 'http.response.start',
+ 'status': 201,
+ 'headers': [(b'content-length', b'0')],
+ }
+ )
+
+
+async def application_200(scope, receive, send):
+ assert scope['type'] == 'http'
+
+ await send(
+ {
+ 'type': 'http.response.start',
+ 'status': 200,
+ 'headers': [(b'content-length', b'0')],
+ }
+ )
+
+
+def legacy_application_200(scope):
+ assert scope['type'] == 'http'
+
+ return legacy_app_http_200
+
+
+async def legacy_app_http_200(receive, send):
+ await send(
+ {
+ 'type': 'http.response.start',
+ 'status': 200,
+ 'headers': [(b'content-length', b'0')],
+ }
+ )
+
+
+def legacy_application_201(scope, receive=None, send=None):
+ assert scope['type'] == 'http'
+
+ return legacy_app_http_201
+
+
+async def legacy_app_http_201(receive, send):
+ await send(
+ {
+ 'type': 'http.response.start',
+ 'status': 201,
+ 'headers': [(b'content-length', b'0')],
+ }
+ )
diff --git a/test/python/targets/wsgi.py b/test/python/targets/wsgi.py
new file mode 100644
index 00000000..fa17ab87
--- /dev/null
+++ b/test/python/targets/wsgi.py
@@ -0,0 +1,8 @@
+def wsgi_target_a(env, start_response):
+ start_response('200', [('Content-Length', '1')])
+ return [b'1']
+
+
+def wsgi_target_b(env, start_response):
+ start_response('200', [('Content-Length', '1')])
+ return [b'2']