From d5e915934066c77a59d211efafca10c117b73d05 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 16 Sep 2020 21:31:15 +0100 Subject: Tests: migrated to the pytest. --- test/test_settings.py | 61 +++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'test/test_settings.py') diff --git a/test/test_settings.py b/test/test_settings.py index 6600358d..59b4a048 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -1,8 +1,9 @@ +import pytest import socket import time -import unittest from unit.applications.lang.python import TestApplicationPython +import re class TestSettings(TestApplicationPython): @@ -32,7 +33,7 @@ Connection: close raw=True, ) - self.assertEqual(resp['status'], 408, 'status header read timeout') + assert resp['status'] == 408, 'status header read timeout' def test_settings_header_read_timeout_update(self): self.load('empty') @@ -83,9 +84,7 @@ Connection: close raw=True, ) - self.assertEqual( - resp['status'], 408, 'status header read timeout update' - ) + assert resp['status'] == 408, 'status header read timeout update' def test_settings_body_read_timeout(self): self.load('empty') @@ -109,7 +108,7 @@ Connection: close resp = self.http(b"""0123456789""", sock=sock, raw=True) - self.assertEqual(resp['status'], 408, 'status body read timeout') + assert resp['status'] == 408, 'status body read timeout' def test_settings_body_read_timeout_update(self): self.load('empty') @@ -144,9 +143,7 @@ Connection: close resp = self.http(b"""6789""", sock=sock, raw=True) - self.assertEqual( - resp['status'], 200, 'status body read timeout update' - ) + assert resp['status'] == 200, 'status body read timeout update' def test_settings_send_timeout(self): self.load('mirror') @@ -155,7 +152,7 @@ Connection: close self.conf({'http': {'send_timeout': 1}}, 'settings') - addr = self.testdir + '/sock' + addr = self.temp_dir + '/sock' self.conf({"unix:" + addr: {'application': 'mirror'}}, 'listeners') @@ -182,13 +179,13 @@ Connection: close sock.close() - self.assertRegex(data, r'200 OK', 'status send timeout') - self.assertLess(len(data), data_len, 'data send timeout') + assert re.search(r'200 OK', data), 'status send timeout' + assert len(data) < data_len, 'data send timeout' def test_settings_idle_timeout(self): self.load('empty') - self.assertEqual(self.get()['status'], 200, 'init') + assert self.get()['status'] == 200, 'init' self.conf({'http': {'idle_timeout': 2}}, 'settings') @@ -204,17 +201,15 @@ Connection: close headers={'Host': 'localhost', 'Connection': 'close'}, sock=sock ) - self.assertEqual(resp['status'], 408, 'status idle timeout') + assert resp['status'] == 408, 'status idle timeout' def test_settings_max_body_size(self): self.load('empty') self.conf({'http': {'max_body_size': 5}}, 'settings') - self.assertEqual(self.post(body='01234')['status'], 200, 'status size') - self.assertEqual( - self.post(body='012345')['status'], 413, 'status size max' - ) + assert self.post(body='01234')['status'] == 200, 'status size' + assert self.post(body='012345')['status'] == 413, 'status size max' def test_settings_max_body_size_large(self): self.load('mirror') @@ -223,32 +218,26 @@ Connection: close body = '0123456789abcdef' * 4 * 64 * 1024 resp = self.post(body=body, read_buffer_size=1024 * 1024) - self.assertEqual(resp['status'], 200, 'status size 4') - self.assertEqual(resp['body'], body, 'status body 4') + assert resp['status'] == 200, 'status size 4' + assert resp['body'] == body, 'status body 4' body = '0123456789abcdef' * 8 * 64 * 1024 resp = self.post(body=body, read_buffer_size=1024 * 1024) - self.assertEqual(resp['status'], 200, 'status size 8') - self.assertEqual(resp['body'], body, 'status body 8') + assert resp['status'] == 200, 'status size 8' + assert resp['body'] == body, 'status body 8' body = '0123456789abcdef' * 16 * 64 * 1024 resp = self.post(body=body, read_buffer_size=1024 * 1024) - self.assertEqual(resp['status'], 200, 'status size 16') - self.assertEqual(resp['body'], body, 'status body 16') + assert resp['status'] == 200, 'status size 16' + assert resp['body'] == body, 'status body 16' body = '0123456789abcdef' * 32 * 64 * 1024 resp = self.post(body=body, read_buffer_size=1024 * 1024) - self.assertEqual(resp['status'], 200, 'status size 32') - self.assertEqual(resp['body'], body, 'status body 32') + assert resp['status'] == 200, 'status size 32' + assert resp['body'] == body, 'status body 32' - @unittest.skip('not yet') + @pytest.mark.skip('not yet') def test_settings_negative_value(self): - self.assertIn( - 'error', - self.conf({'http': {'max_body_size': -1}}, 'settings'), - 'settings negative value', - ) - - -if __name__ == '__main__': - TestSettings.main() + assert 'error' in self.conf( + {'http': {'max_body_size': -1}}, 'settings' + ), 'settings negative value' -- cgit From 39008c1f05b30e9ac51cf7c46743c9d2dc34f505 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 21 Sep 2020 21:24:42 +0100 Subject: Tests: added test for "idle_timeout" with empty payload. --- test/test_settings.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/test_settings.py') diff --git a/test/test_settings.py b/test/test_settings.py index 59b4a048..797af5ed 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -203,6 +203,24 @@ Connection: close assert resp['status'] == 408, 'status idle timeout' + def test_settings_idle_timeout_2(self): + self.load('empty') + + assert self.get()['status'] == 200, 'init' + + self.conf({'http': {'idle_timeout': 1}}, 'settings') + + _, sock = self.http(b'', start=True, raw=True, no_recv=True) + + time.sleep(2) + + assert ( + self.get( + headers={'Host': 'localhost', 'Connection': 'close'}, sock=sock + )['status'] + == 408 + ), 'status idle timeout' + def test_settings_max_body_size(self): self.load('empty') -- cgit From 4de6ffa63fb11bc37d47dcddc305bbf6f5768a84 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Sun, 27 Sep 2020 23:46:31 +0100 Subject: Tests: tuned delay in test_settings_idle_timeout_2. --- test/test_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_settings.py') diff --git a/test/test_settings.py b/test/test_settings.py index 797af5ed..89f55703 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -212,7 +212,7 @@ Connection: close _, sock = self.http(b'', start=True, raw=True, no_recv=True) - time.sleep(2) + time.sleep(3) assert ( self.get( -- cgit From 6ec0ff35964c7805712d978625949f72ff5a63bc Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 7 Oct 2020 23:18:43 +0100 Subject: Tests: minor fixes. --- test/test_settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/test_settings.py') diff --git a/test/test_settings.py b/test/test_settings.py index 89f55703..b0af6b04 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -1,9 +1,10 @@ -import pytest +import re import socket import time +import pytest + from unit.applications.lang.python import TestApplicationPython -import re class TestSettings(TestApplicationPython): -- cgit