Tests: more Python tests.

This commit is contained in:
Andrey Zelenkov
2018-04-02 17:03:41 +03:00
parent efb71121b9
commit a01a98ce36
17 changed files with 215 additions and 69 deletions

View File

@@ -1,12 +1,10 @@
import atexit
def application(environ, start_response):
test_dir = environ.get('HTTP_TEST_DIR')
def at_exit():
environ['wsgi.errors'].write('At exit called.')
def create_file():
open(test_dir + '/atexit', 'w')
atexit.register(create_file)
atexit.register(at_exit)
start_response('200', [('Content-Length', '0')])
return []

View File

@@ -0,0 +1,3 @@
def application(env, start_response):
start_response('200', [('Content-Length', '10')])
return [b'0123', b'4567', b'89']

View File

@@ -0,0 +1,6 @@
import io
def application(env, start_response):
start_response('200', [('Content-Length', '10')])
f = io.BytesIO(b'0123456789')
return f

View File

@@ -0,0 +1 @@
body

View File

@@ -0,0 +1,4 @@
def application(env, start_response):
start_response('200', [('Content-Length', '5')])
f = open('file', 'rb')
return f

10
test/python/close/wsgi.py Normal file
View File

@@ -0,0 +1,10 @@
class application:
def __init__(self, environ, start_response):
self.environ = environ
self.start = start_response
def __iter__(self):
self.start('200', [(('Content-Length', '0'))])
def close(self):
self.environ['wsgi.errors'].write('Close called.')

View File

@@ -0,0 +1,10 @@
class application:
def __init__(self, environ, start_response):
self.environ = environ
self.start = start_response
def __iter__(self):
self.start('200', [(('!', '0'))])
def close(self):
self.environ['wsgi.errors'].write('Close called.')

View File

@@ -0,0 +1,5 @@
def application(environ, start_response):
environ['wsgi.errors'].write('Error in application.')
start_response('200', [('Content-Length', '0')])
return []

View File

@@ -0,0 +1,5 @@
def application(environ, start_response):
body = bytes(environ['wsgi.input'].__iter__())
start_response('200', [('Content-Length', str(len(body)))])
return [body]

View File

@@ -0,0 +1,7 @@
def application(environ, start_response):
input_length = int(environ.get('HTTP_INPUT_LENGTH'))
body = bytes(environ['wsgi.input'].read(input_length))
start_response('200', [('Content-Length', str(len(body)))])
return [body]

View File

@@ -0,0 +1,4 @@
def application(env, start_response):
start_response('200', [('Content-Length', '1')])
exit()
return [b'X']

View File

@@ -0,0 +1,3 @@
def application(env, start_response)
start_response('200', [('Content-Length', '0')])
return []

View File

@@ -10,6 +10,11 @@ def application(environ, start_response):
('Request-Uri', environ.get('REQUEST_URI')),
('Http-Host', environ.get('HTTP_HOST')),
('Server-Protocol', environ.get('SERVER_PROTOCOL')),
('Custom-Header', environ.get('HTTP_CUSTOM_HEADER'))
('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')),
('Wsgi-Version', str(environ['wsgi.version'])),
('Wsgi-Url-Scheme', environ['wsgi.url_scheme']),
('Wsgi-Multithread', str(environ['wsgi.multithread'])),
('Wsgi-Multiprocess', str(environ['wsgi.multiprocess'])),
('Wsgi-Run-Once', str(environ['wsgi.run_once']))
])
return [body]