diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-02-20 20:34:41 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-02-20 20:34:41 +0300 |
commit | 09f2009df564ab2063ee4713ba24247039945146 (patch) | |
tree | 5c719060dd4af2ca932da96d93d77eeebc6c5f25 /test/test_python_application.py | |
parent | babf67712e4226527730e2fb8c96babdf5486ca5 (diff) | |
download | unit-09f2009df564ab2063ee4713ba24247039945146.tar.gz unit-09f2009df564ab2063ee4713ba24247039945146.tar.bz2 |
Tests: reworked python tests with application.
Diffstat (limited to '')
-rw-r--r-- | test/test_python_application.py | 86 |
1 files changed, 6 insertions, 80 deletions
diff --git a/test/test_python_application.py b/test/test_python_application.py index 80854eb5..00b901bc 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -2,51 +2,13 @@ import time import unittest import unit -class TestUnitPythonApplication(unit.TestUnitControl): +class TestUnitPythonApplication(unit.TestUnitApplicationPython): def setUpClass(): unit.TestUnit().check_modules('python') - def conf_with_name(self, name): - self.conf({ - "listeners": { - "*:7080": { - "application": "app" - } - }, - "applications": { - "app": { - "type": "python", - "processes": { "spare": 0 }, - "path": self.testdir + '/' + name, - "module": "wsgi" - } - } - }) - - def test_python_application_simple(self): - code, name = """ - -def application(environ, start_response): - - content_length = int(environ.get('CONTENT_LENGTH', 0)) - body = bytes(environ['wsgi.input'].read(content_length)) - - start_response('200', [ - ('Content-Type', environ.get('CONTENT_TYPE')), - ('Content-Length', str(len(body))), - ('Request-Method', environ.get('REQUEST_METHOD')), - ('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')) - ]) - return [body] - -""", 'py_app' - - self.python_application(name, code) - self.conf_with_name(name) + def test_python_application_variables(self): + self.load('variables') body = 'Test body string.' @@ -75,20 +37,7 @@ def application(environ, start_response): self.assertEqual(resp['body'], body, 'body') def test_python_application_query_string(self): - code, name = """ - -def application(environ, start_response): - - start_response('200', [ - ('Content-Length', '0'), - ('Query-String', environ.get('QUERY_STRING')) - ]) - return [] - -""", 'py_app' - - self.python_application(name, code) - self.conf_with_name(name) + self.load('query_string') resp = self.get(url='/?var1=val1&var2=val2') @@ -97,37 +46,14 @@ def application(environ, start_response): @unittest.expectedFailure def test_python_application_server_port(self): - code, name = """ - -def application(environ, start_response): - - start_response('200', [ - ('Content-Length', '0'), - ('Server-Port', environ.get('SERVER_PORT')) - ]) - return [] - -""", 'py_app' - - self.python_application(name, code) - self.conf_with_name(name) + self.load('server_port') self.assertEqual(self.get()['headers']['Server-Port'], '7080', 'Server-Port header') @unittest.expectedFailure def test_python_application_204_transfer_encoding(self): - code, name = """ - -def application(environ, start_response): - - start_response('204 No Content', []) - return [] - -""", 'py_app' - - self.python_application(name, code) - self.conf_with_name(name) + self.load('204_no_content') self.assertNotIn('Transfer-Encoding', self.get()['headers'], '204 header transfer encoding') |