From 281899fcef10eaf815d90958d49243c5060ffac0 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Tue, 26 Mar 2019 23:38:30 +0300 Subject: Tests: style. --- test/test_go_application.py | 144 +++++++++++++++++++++++++++----------------- 1 file changed, 90 insertions(+), 54 deletions(-) (limited to 'test/test_go_application.py') 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'404 Not Found', - '404 body') + self.assertRegex( + resp['body'], r'404 Not Found', '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() -- cgit From 19eba1730a1ca839ed62a37f34c204f580d1b653 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Thu, 28 Mar 2019 18:43:13 +0300 Subject: Tests: unit module refactoring. --- test/test_go_application.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/test_go_application.py') diff --git a/test/test_go_application.py b/test/test_go_application.py index 9b39b238..8c06d583 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -1,10 +1,10 @@ import unittest -import unit +from unit.applications.lang.go import TestApplicationGo -class TestUnitGoApplication(unit.TestUnitApplicationGo): +class TestGoApplication(TestApplicationGo): def setUpClass(): - unit.TestUnit().check_modules('go') + TestApplicationGo().check_modules('go') def test_go_application_variables(self): self.load('variables') @@ -184,4 +184,4 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): if __name__ == '__main__': - TestUnitGoApplication.main() + TestGoApplication.main() -- cgit From af24e4dec453af7e3dcb45347cb59bfcbc037843 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Tue, 9 Apr 2019 16:14:42 +0300 Subject: Tests: simplified module checking. --- test/test_go_application.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/test_go_application.py') diff --git a/test/test_go_application.py b/test/test_go_application.py index 8c06d583..0f66a730 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -3,8 +3,7 @@ from unit.applications.lang.go import TestApplicationGo class TestGoApplication(TestApplicationGo): - def setUpClass(): - TestApplicationGo().check_modules('go') + prerequisites = ['go'] def test_go_application_variables(self): self.load('variables') -- cgit From 29b4e4431fe43f9ac969a1cdb67478da8c5dcc1e Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Tue, 9 Apr 2019 20:59:35 +0300 Subject: Tests: speed up tests. --- test/test_go_application.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/test_go_application.py') diff --git a/test/test_go_application.py b/test/test_go_application.py index 0f66a730..373fcdf3 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -88,6 +88,8 @@ class TestGoApplication(TestApplicationGo): def test_go_keepalive_body(self): self.load('mirror') + self.assertEqual(self.get()['status'], 200, 'init') + (resp, sock) = self.post( headers={ 'Host': 'localhost', @@ -96,6 +98,7 @@ class TestGoApplication(TestApplicationGo): }, start=True, body='0123456789' * 500, + read_timeout=1, ) self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') -- cgit From 90c5d3f5c0ad42ccdb764684f721b511131e0782 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Thu, 30 May 2019 16:46:04 +0300 Subject: Tests: adjusted skipping tests. --- test/test_go_application.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test/test_go_application.py') diff --git a/test/test_go_application.py b/test/test_go_application.py index 373fcdf3..488bfdd5 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -1,4 +1,3 @@ -import unittest from unit.applications.lang.go import TestApplicationGo -- cgit