diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-04-02 17:03:41 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-04-02 17:03:41 +0300 |
commit | a01a98ce36dd47c1be1df37470cac1656efac31e (patch) | |
tree | a2b962d568e14562b9274d142b239eedc6eae1df /test/python | |
parent | efb71121b98c4dfded212e8b6fe33873cfd83376 (diff) | |
download | unit-a01a98ce36dd47c1be1df37470cac1656efac31e.tar.gz unit-a01a98ce36dd47c1be1df37470cac1656efac31e.tar.bz2 |
Tests: more Python tests.
Diffstat (limited to 'test/python')
-rw-r--r-- | test/python/atexit/wsgi.py | 8 | ||||
-rw-r--r-- | test/python/body_array/wsgi.py | 3 | ||||
-rw-r--r-- | test/python/body_io/wsgi.py | 6 | ||||
-rw-r--r-- | test/python/body_io_file/file | 1 | ||||
-rw-r--r-- | test/python/body_io_file/wsgi.py | 4 | ||||
-rw-r--r-- | test/python/close/wsgi.py | 10 | ||||
-rw-r--r-- | test/python/close_error/wsgi.py | 10 | ||||
-rw-r--r-- | test/python/errors_write/wsgi.py | 5 | ||||
-rw-r--r-- | test/python/input_iter/wsgi.py | 5 | ||||
-rw-r--r-- | test/python/input_read_length/wsgi.py | 7 | ||||
-rw-r--r-- | test/python/start_response_exit/wsgi.py | 4 | ||||
-rw-r--r-- | test/python/syntax_error/wsgi.py | 3 | ||||
-rw-r--r-- | test/python/variables/wsgi.py | 7 |
13 files changed, 67 insertions, 6 deletions
diff --git a/test/python/atexit/wsgi.py b/test/python/atexit/wsgi.py index 9ad300b9..561d8049 100644 --- a/test/python/atexit/wsgi.py +++ b/test/python/atexit/wsgi.py @@ -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 [] diff --git a/test/python/body_array/wsgi.py b/test/python/body_array/wsgi.py new file mode 100644 index 00000000..2390f222 --- /dev/null +++ b/test/python/body_array/wsgi.py @@ -0,0 +1,3 @@ +def application(env, start_response): + start_response('200', [('Content-Length', '10')]) + return [b'0123', b'4567', b'89'] diff --git a/test/python/body_io/wsgi.py b/test/python/body_io/wsgi.py new file mode 100644 index 00000000..14303b5f --- /dev/null +++ b/test/python/body_io/wsgi.py @@ -0,0 +1,6 @@ +import io + +def application(env, start_response): + start_response('200', [('Content-Length', '10')]) + f = io.BytesIO(b'0123456789') + return f diff --git a/test/python/body_io_file/file b/test/python/body_io_file/file new file mode 100644 index 00000000..273a402f --- /dev/null +++ b/test/python/body_io_file/file @@ -0,0 +1 @@ +body diff --git a/test/python/body_io_file/wsgi.py b/test/python/body_io_file/wsgi.py new file mode 100644 index 00000000..713e341b --- /dev/null +++ b/test/python/body_io_file/wsgi.py @@ -0,0 +1,4 @@ +def application(env, start_response): + start_response('200', [('Content-Length', '5')]) + f = open('file', 'rb') + return f diff --git a/test/python/close/wsgi.py b/test/python/close/wsgi.py new file mode 100644 index 00000000..f80a34d7 --- /dev/null +++ b/test/python/close/wsgi.py @@ -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.') diff --git a/test/python/close_error/wsgi.py b/test/python/close_error/wsgi.py new file mode 100644 index 00000000..bd9d4d36 --- /dev/null +++ b/test/python/close_error/wsgi.py @@ -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.') diff --git a/test/python/errors_write/wsgi.py b/test/python/errors_write/wsgi.py new file mode 100644 index 00000000..b1a9d2ee --- /dev/null +++ b/test/python/errors_write/wsgi.py @@ -0,0 +1,5 @@ +def application(environ, start_response): + environ['wsgi.errors'].write('Error in application.') + + start_response('200', [('Content-Length', '0')]) + return [] diff --git a/test/python/input_iter/wsgi.py b/test/python/input_iter/wsgi.py new file mode 100644 index 00000000..d3bf437f --- /dev/null +++ b/test/python/input_iter/wsgi.py @@ -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] diff --git a/test/python/input_read_length/wsgi.py b/test/python/input_read_length/wsgi.py new file mode 100644 index 00000000..9d209556 --- /dev/null +++ b/test/python/input_read_length/wsgi.py @@ -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] diff --git a/test/python/start_response_exit/wsgi.py b/test/python/start_response_exit/wsgi.py new file mode 100644 index 00000000..37c3acfe --- /dev/null +++ b/test/python/start_response_exit/wsgi.py @@ -0,0 +1,4 @@ +def application(env, start_response): + start_response('200', [('Content-Length', '1')]) + exit() + return [b'X'] diff --git a/test/python/syntax_error/wsgi.py b/test/python/syntax_error/wsgi.py new file mode 100644 index 00000000..0ac759de --- /dev/null +++ b/test/python/syntax_error/wsgi.py @@ -0,0 +1,3 @@ +def application(env, start_response) + start_response('200', [('Content-Length', '0')]) + return [] diff --git a/test/python/variables/wsgi.py b/test/python/variables/wsgi.py index 1d4d397d..60fa3401 100644 --- a/test/python/variables/wsgi.py +++ b/test/python/variables/wsgi.py @@ -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] |