diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2019-03-26 23:38:30 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2019-03-26 23:38:30 +0300 |
commit | 281899fcef10eaf815d90958d49243c5060ffac0 (patch) | |
tree | 258d01fb832a4253815db41673c9fcc73f128e6b /test/test_go_application.py | |
parent | 3d7a47c9acb1120f90225c833fd56cffeb99c2cd (diff) | |
download | unit-281899fcef10eaf815d90958d49243c5060ffac0.tar.gz unit-281899fcef10eaf815d90958d49243c5060ffac0.tar.bz2 |
Tests: style.
Diffstat (limited to '')
-rw-r--r-- | test/test_go_application.py | 144 |
1 files changed, 90 insertions, 54 deletions
diff --git a/test/test_go_application.py b/test/test_go_application.py index 1ecc2536..9b39b238 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -1,8 +1,8 @@ import unittest import unit -class TestUnitGoApplication(unit.TestUnitApplicationGo): +class TestUnitGoApplication(unit.TestUnitApplicationGo): def setUpClass(): unit.TestUnit().check_modules('go') @@ -11,12 +11,15 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): body = 'Test body string.' - resp = self.post(headers={ - 'Host': 'localhost', - 'Content-Type': 'text/html', - 'Custom-Header': 'blah', - 'Connection': 'close' - }, body=body) + resp = self.post( + headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html', + 'Custom-Header': 'blah', + 'Connection': 'close', + }, + body=body, + ) self.assertEqual(resp['status'], 200, 'status') headers = resp['headers'] @@ -25,21 +28,28 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): date = headers.pop('Date') self.assertEqual(date[-4:], ' GMT', 'date header timezone') - self.assertLess(abs(self.date_to_sec_epoch(date) - self.sec_epoch()), 5, - 'date header') - - self.assertDictEqual(headers, { - 'Content-Length': str(len(body)), - 'Content-Type': 'text/html', - 'Request-Method': 'POST', - 'Request-Uri': '/', - 'Http-Host': 'localhost', - 'Server-Protocol': 'HTTP/1.1', - 'Server-Protocol-Major': '1', - 'Server-Protocol-Minor': '1', - 'Custom-Header': 'blah', - 'Connection': 'close' - }, 'headers') + self.assertLess( + abs(self.date_to_sec_epoch(date) - self.sec_epoch()), + 5, + 'date header', + ) + + self.assertDictEqual( + headers, + { + 'Content-Length': str(len(body)), + 'Content-Type': 'text/html', + 'Request-Method': 'POST', + 'Request-Uri': '/', + 'Http-Host': 'localhost', + 'Server-Protocol': 'HTTP/1.1', + 'Server-Protocol-Major': '1', + 'Server-Protocol-Minor': '1', + 'Custom-Header': 'blah', + 'Connection': 'close', + }, + 'headers', + ) self.assertEqual(resp['body'], body, 'body') def test_go_application_get_variables(self): @@ -53,11 +63,14 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): def test_go_application_post_variables(self): self.load('post_variables') - resp = self.post(headers={ - 'Host': 'localhost', - 'Content-Type': 'application/x-www-form-urlencoded', - 'Connection': 'close' - }, body='var1=val1&var2=&var3') + resp = self.post( + headers={ + 'Host': 'localhost', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Connection': 'close', + }, + body='var1=val1&var2=&var3', + ) self.assertEqual(resp['headers']['X-Var-1'], 'val1', 'POST variables') self.assertEqual(resp['headers']['X-Var-2'], '', 'POST variables 2') @@ -69,36 +82,47 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): resp = self.get() self.assertEqual(resp['status'], 404, '404 status') - self.assertRegex(resp['body'], r'<title>404 Not Found</title>', - '404 body') + self.assertRegex( + resp['body'], r'<title>404 Not Found</title>', '404 body' + ) def test_go_keepalive_body(self): self.load('mirror') - (resp, sock) = self.post(headers={ - 'Host': 'localhost', - 'Connection': 'keep-alive', - 'Content-Type': 'text/html' - }, start=True, body='0123456789' * 500) + (resp, sock) = self.post( + headers={ + 'Host': 'localhost', + 'Connection': 'keep-alive', + 'Content-Type': 'text/html', + }, + start=True, + body='0123456789' * 500, + ) self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') - resp = self.post(headers={ - 'Host': 'localhost', - 'Content-Type': 'text/html', - 'Connection': 'close' - }, sock=sock, body='0123456789') + resp = self.post( + headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html', + 'Connection': 'close', + }, + sock=sock, + body='0123456789', + ) self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') def test_go_application_cookies(self): self.load('cookies') - resp = self.get(headers={ - 'Host': 'localhost', - 'Cookie': 'var1=val1; var2=val2', - 'Connection': 'close' - }) + resp = self.get( + headers={ + 'Host': 'localhost', + 'Cookie': 'var1=val1; var2=val2', + 'Connection': 'close', + } + ) self.assertEqual(resp['headers']['X-Cookie-1'], 'val1', 'cookie 1') self.assertEqual(resp['headers']['X-Cookie-2'], 'val2', 'cookie 2') @@ -106,15 +130,22 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): def test_go_application_command_line_arguments_type(self): self.load('command_line_arguments') - self.assertIn('error', self.conf(''"a b c", - 'applications/command_line_arguments/arguments'), 'arguments type') + self.assertIn( + 'error', + self.conf( + '' "a b c", 'applications/command_line_arguments/arguments' + ), + 'arguments type', + ) def test_go_application_command_line_arguments_0(self): self.load('command_line_arguments') - self.assertEqual(self.get()['headers']['X-Arg-0'], + self.assertEqual( + self.get()['headers']['X-Arg-0'], self.conf_get('applications/command_line_arguments/executable'), - 'argument 0') + 'argument 0', + ) def test_go_application_command_line_arguments(self): self.load('command_line_arguments') @@ -123,11 +154,14 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): arg2 = '--cc-opt=\'-O0 -DNXT_DEBUG_MEMORY=1 -fsanitize=address\'' arg3 = '--debug' - self.conf('["' + arg1 + '", "' + arg2 + '", "' + arg3 + '"]', - 'applications/command_line_arguments/arguments') + self.conf( + '["' + arg1 + '", "' + arg2 + '", "' + arg3 + '"]', + 'applications/command_line_arguments/arguments', + ) - self.assertEqual(self.get()['body'], arg1 + ',' + arg2 + ',' + arg3, - 'arguments') + self.assertEqual( + self.get()['body'], arg1 + ',' + arg2 + ',' + arg3, 'arguments' + ) def test_go_application_command_line_arguments_change(self): self.load('command_line_arguments') @@ -144,8 +178,10 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): self.conf('[]', args_path) - self.assertEqual(self.get()['headers']['Content-Length'], '0', - 'arguments empty') + self.assertEqual( + self.get()['headers']['Content-Length'], '0', 'arguments empty' + ) + if __name__ == '__main__': TestUnitGoApplication.main() |