diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-01-17 15:52:01 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-01-17 15:52:01 +0300 |
commit | a949c2f08818bb9a8c8e54ed35e2a4a95a07acd3 (patch) | |
tree | 736d44e5f2ec188c47312d8cd9e2310312f00bff /test/test_python_application.py | |
parent | 37a713c217d132df89dc3726c33e4e96456d4433 (diff) | |
download | unit-a949c2f08818bb9a8c8e54ed35e2a4a95a07acd3.tar.gz unit-a949c2f08818bb9a8c8e54ed35e2a4a95a07acd3.tar.bz2 |
Tests: using LF line ending for test files.
Diffstat (limited to 'test/test_python_application.py')
-rw-r--r-- | test/test_python_application.py | 180 |
1 files changed, 90 insertions, 90 deletions
diff --git a/test/test_python_application.py b/test/test_python_application.py index 5066624a..7014036b 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -1,90 +1,90 @@ -import unittest
-import unit
-
-class TestUnitApplication(unit.TestUnitControl):
-
- def setUpClass():
- u = unit.TestUnit()
-
- u.check_modules('python')
- u.check_version('0.4')
-
- def test_python_application(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 OK', [
- ('Content-Type', environ.get('CONTENT_TYPE')),
- ('Content-Length', str(len(body))),
- ('Request-Method', environ.get('REQUEST_METHOD')),
- ('Request-Uri', environ.get('REQUEST_URI')),
- ('Path-Info', environ.get('PATH_INFO')),
- ('Http-Host', environ.get('HTTP_HOST')),
- ('Remote-Addr', environ.get('REMOTE_ADDR')),
- ('Server-Name', environ.get('SERVER_NAME')),
- ('Server-Port', environ.get('SERVER_PORT')),
- ('Server-Protocol', environ.get('SERVER_PROTOCOL')),
- ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER'))
- ])
- return [body]
-
-""", 'py_app'
-
- self.python_application(name, code)
-
- self.put('/', """
- {
- "listeners": {
- "*:7080": {
- "application": "app"
- }
- },
- "applications": {
- "app": {
- "type": "python",
- "workers": 1,
- "path": "%s",
- "module": "wsgi"
- }
- }
- }
- """ % (self.testdir + '/' + name))
-
- body = 'Test body string.'
-
- r = unit.TestUnitHTTP.post(headers={
- 'Host': 'localhost',
- 'Content-Type': 'text/html',
- 'Custom-Header': 'blah'
- }, data=body)
-
- self.assertEqual(r.status_code, 200, 'status')
- self.assertEqual(r.headers['Content-Length'], str(len(body)),
- 'header content length')
- self.assertEqual(r.headers['Content-Type'], 'text/html',
- 'header content type')
- self.assertEqual(r.headers['Request-Method'], 'POST',
- 'header request method')
- self.assertEqual(r.headers['Request-Uri'], '/', 'header request uri')
- self.assertEqual(r.headers['Path-Info'], '/', 'header path info')
- self.assertEqual(r.headers['Http-Host'], 'localhost',
- 'header http host')
- self.assertEqual(r.headers['Remote-Addr'], '127.0.0.1',
- 'header remote addr')
-
- self.assertTry('assertEqual', 'header server port',
- r.headers['Server-Port'], '7080')
-
- self.assertEqual(r.headers['Server-Protocol'], 'HTTP/1.1',
- 'header server protocol')
- self.assertEqual(r.headers['Custom-Header'], 'blah',
- 'header custom header')
- self.assertEqual(r.content, str.encode(body), 'body')
-
-
-if __name__ == '__main__':
- unittest.main()
+import unittest +import unit + +class TestUnitApplication(unit.TestUnitControl): + + def setUpClass(): + u = unit.TestUnit() + + u.check_modules('python') + u.check_version('0.4') + + def test_python_application(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 OK', [ + ('Content-Type', environ.get('CONTENT_TYPE')), + ('Content-Length', str(len(body))), + ('Request-Method', environ.get('REQUEST_METHOD')), + ('Request-Uri', environ.get('REQUEST_URI')), + ('Path-Info', environ.get('PATH_INFO')), + ('Http-Host', environ.get('HTTP_HOST')), + ('Remote-Addr', environ.get('REMOTE_ADDR')), + ('Server-Name', environ.get('SERVER_NAME')), + ('Server-Port', environ.get('SERVER_PORT')), + ('Server-Protocol', environ.get('SERVER_PROTOCOL')), + ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')) + ]) + return [body] + +""", 'py_app' + + self.python_application(name, code) + + self.put('/', """ + { + "listeners": { + "*:7080": { + "application": "app" + } + }, + "applications": { + "app": { + "type": "python", + "workers": 1, + "path": "%s", + "module": "wsgi" + } + } + } + """ % (self.testdir + '/' + name)) + + body = 'Test body string.' + + r = unit.TestUnitHTTP.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html', + 'Custom-Header': 'blah' + }, data=body) + + self.assertEqual(r.status_code, 200, 'status') + self.assertEqual(r.headers['Content-Length'], str(len(body)), + 'header content length') + self.assertEqual(r.headers['Content-Type'], 'text/html', + 'header content type') + self.assertEqual(r.headers['Request-Method'], 'POST', + 'header request method') + self.assertEqual(r.headers['Request-Uri'], '/', 'header request uri') + self.assertEqual(r.headers['Path-Info'], '/', 'header path info') + self.assertEqual(r.headers['Http-Host'], 'localhost', + 'header http host') + self.assertEqual(r.headers['Remote-Addr'], '127.0.0.1', + 'header remote addr') + + self.assertTry('assertEqual', 'header server port', + r.headers['Server-Port'], '7080') + + self.assertEqual(r.headers['Server-Protocol'], 'HTTP/1.1', + 'header server protocol') + self.assertEqual(r.headers['Custom-Header'], 'blah', + 'header custom header') + self.assertEqual(r.content, str.encode(body), 'body') + + +if __name__ == '__main__': + unittest.main() |