From 3e4fa1e2022970dee003bea0932ea0c10f8744ba Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 25 May 2023 14:26:12 +0100 Subject: Tests: removed unused variables. --- test/unit/applications/proto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/applications') diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index f04ee408..f4d4afe4 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -26,7 +26,7 @@ class TestApplicationProto(TestControl): def wait_for_record(self, pattern, name='unit.log', wait=150, flags=re.M): with Log.open(name) as f: - for i in range(wait): + for _ in range(wait): found = re.search(pattern, f.read(), flags) if found is not None: -- cgit From f55818059c01ff9e61bee8107ed1389fe272a787 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 29 May 2023 14:23:52 +0100 Subject: Tests: Log reworked. All log-related code moved to the log.py. --- test/unit/applications/proto.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test/unit/applications') diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index f4d4afe4..3f4c13d3 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -17,12 +17,10 @@ class TestApplicationProto(TestControl): return time.mktime(time.strptime(date, template)) def findall(self, pattern, name='unit.log', flags=re.M): - with Log.open(name) as f: - return re.findall(pattern, f.read(), flags) + return re.findall(pattern, Log.read(name), flags) def search_in_log(self, pattern, name='unit.log', flags=re.M): - with Log.open(name) as f: - return re.search(pattern, f.read(), flags) + return re.search(pattern, Log.read(name), flags) def wait_for_record(self, pattern, name='unit.log', wait=150, flags=re.M): with Log.open(name) as f: -- cgit From 31ff94add9c4043a753683d9e8b68733c69aa1ac Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 29 May 2023 16:45:49 +0100 Subject: Tests: more fixtures. Common methods from applications/proto.py converted to the fixtures. sysctl check moved to the specific file where it is using. Some options moved to the constructor to have early access. --- test/unit/applications/proto.py | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'test/unit/applications') diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index 3f4c13d3..00ea44b2 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -10,30 +10,6 @@ from unit.option import option class TestApplicationProto(TestControl): application_type = None - def sec_epoch(self): - return time.mktime(time.gmtime()) - - def date_to_sec_epoch(self, date, template='%a, %d %b %Y %X %Z'): - return time.mktime(time.strptime(date, template)) - - def findall(self, pattern, name='unit.log', flags=re.M): - return re.findall(pattern, Log.read(name), flags) - - def search_in_log(self, pattern, name='unit.log', flags=re.M): - return re.search(pattern, Log.read(name), flags) - - def wait_for_record(self, pattern, name='unit.log', wait=150, flags=re.M): - with Log.open(name) as f: - for _ in range(wait): - found = re.search(pattern, f.read(), flags) - - if found is not None: - break - - time.sleep(0.1) - - return found - def get_application_type(self): current_test = ( os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0] -- cgit From ce2405ec3dd97e8bdf8f63312e3c6ce59ef562d4 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 12 Jun 2023 14:16:59 +0100 Subject: Tests: prerequisites checking reworked. Prerequisites check moved to the module level to simplify class structure. Discovery and prerequisites checks functions moved to the separate files. Introduced "require" fixture to provide per-test requirements check. --- test/unit/applications/proto.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'test/unit/applications') diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index 00ea44b2..354c31af 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -1,9 +1,6 @@ import os -import re -import time from unit.control import TestControl -from unit.log import Log from unit.option import option -- cgit From c183bd8749a19477390f8cb77efe5f6d223f0905 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 14 Jun 2023 18:20:09 +0100 Subject: Tests: get rid of classes in test files. Class usage came from the unittest framework and it was always redundant after migration to the pytest. This commit removes classes from files containing tests to make them more readable and understandable. --- test/unit/applications/lang/go.py | 6 +++--- test/unit/applications/lang/java.py | 7 ++++--- test/unit/applications/lang/node.py | 9 +++++---- test/unit/applications/lang/perl.py | 7 ++++--- test/unit/applications/lang/php.py | 7 ++++--- test/unit/applications/lang/python.py | 9 +++++---- test/unit/applications/lang/ruby.py | 7 ++++--- test/unit/applications/proto.py | 4 ++-- test/unit/applications/tls.py | 18 ++++++++++-------- test/unit/applications/websockets.py | 4 ++-- 10 files changed, 43 insertions(+), 35 deletions(-) (limited to 'test/unit/applications') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 557753a4..93e0738b 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -2,11 +2,11 @@ import os import shutil import subprocess -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option -class TestApplicationGo(TestApplicationProto): +class ApplicationGo(ApplicationProto): @staticmethod def prepare_env(script, name='app', static=False): try: @@ -88,7 +88,7 @@ replace unit.nginx.org/go => {replace_path} executable = f"/go/{name}" static_build = True - TestApplicationGo.prepare_env(script, name, static=static_build) + ApplicationGo.prepare_env(script, name, static=static_build) conf = { "listeners": {"*:7080": {"pass": f"applications/{script}"}}, diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index b6382cfe..f6f71b7d 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -4,12 +4,13 @@ import shutil import subprocess import pytest -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option -class TestApplicationJava(TestApplicationProto): - application_type = "java" +class ApplicationJava(ApplicationProto): + def __init__(self, application_type='java'): + self.application_type = application_type def prepare_env(self, script): app_path = f'{option.temp_dir}/java' diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index 87d5a19c..4f18c780 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -1,14 +1,15 @@ import shutil from urllib.parse import quote -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option from unit.utils import public_dir -class TestApplicationNode(TestApplicationProto): - application_type = "node" - es_modules = False +class ApplicationNode(ApplicationProto): + def __init__(self, application_type='node', es_modules=False): + self.application_type = application_type + self.es_modules = es_modules def prepare_env(self, script): # copy application diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py index 19852363..037e98e8 100644 --- a/test/unit/applications/lang/perl.py +++ b/test/unit/applications/lang/perl.py @@ -1,9 +1,10 @@ -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option -class TestApplicationPerl(TestApplicationProto): - application_type = "perl" +class ApplicationPerl(ApplicationProto): + def __init__(self, application_type='perl'): + self.application_type = application_type def load(self, script, name='psgi.pl', **kwargs): script_path = f'{option.test_dir}/perl/{script}' diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index 1b94c3ae..b9b6dbf1 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -1,12 +1,13 @@ import os import shutil -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option -class TestApplicationPHP(TestApplicationProto): - application_type = "php" +class ApplicationPHP(ApplicationProto): + def __init__(self, application_type='php'): + self.application_type = application_type def load(self, script, index='index.php', **kwargs): script_path = f'{option.test_dir}/php/{script}' diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 0bb69992..4e1fd897 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -2,13 +2,14 @@ import os import shutil from urllib.parse import quote -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option -class TestApplicationPython(TestApplicationProto): - application_type = "python" - load_module = "wsgi" +class ApplicationPython(ApplicationProto): + def __init__(self, application_type='python', load_module='wsgi'): + self.application_type = application_type + self.load_module = load_module def load(self, script, name=None, module=None, **kwargs): if name is None: diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py index e0712fc6..f6c4f6c3 100644 --- a/test/unit/applications/lang/ruby.py +++ b/test/unit/applications/lang/ruby.py @@ -1,12 +1,13 @@ import shutil -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option from unit.utils import public_dir -class TestApplicationRuby(TestApplicationProto): - application_type = "ruby" +class ApplicationRuby(ApplicationProto): + def __init__(self, application_type='ruby'): + self.application_type = application_type def prepare_env(self, script): shutil.copytree( diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index 354c31af..7a1636c6 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -1,10 +1,10 @@ import os -from unit.control import TestControl +from unit.control import Control from unit.option import option -class TestApplicationProto(TestControl): +class ApplicationProto(Control): application_type = None def get_application_type(self): diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py index e5813312..e9bcc514 100644 --- a/test/unit/applications/tls.py +++ b/test/unit/applications/tls.py @@ -2,15 +2,15 @@ import os import ssl import subprocess -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto from unit.option import option -class TestApplicationTLS(TestApplicationProto): - def setup_method(self): - self.context = ssl.create_default_context() - self.context.check_hostname = False - self.context.verify_mode = ssl.CERT_NONE +class ApplicationTLS(ApplicationProto): + def __init__(self): + self._default_context = ssl.create_default_context() + self._default_context.check_hostname = False + self._default_context.verify_mode = ssl.CERT_NONE def certificate(self, name='default', load=True): self.openssl_conf() @@ -47,10 +47,12 @@ class TestApplicationTLS(TestApplicationProto): return self.conf(k.read() + c.read(), f'/certificates/{crt}') def get_ssl(self, **kwargs): - return self.get(wrapper=self.context.wrap_socket, **kwargs) + context = kwargs.get('context', self._default_context) + return self.get(wrapper=context.wrap_socket, **kwargs) def post_ssl(self, **kwargs): - return self.post(wrapper=self.context.wrap_socket, **kwargs) + context = kwargs.get('context', self._default_context) + return self.post(wrapper=context.wrap_socket, **kwargs) def openssl_conf(self, rewrite=False, alt_names=None): alt_names = alt_names or [] diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index a4b9287d..29725943 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -6,12 +6,12 @@ import select import struct import pytest -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" -class TestApplicationWebsocket(TestApplicationProto): +class ApplicationWebsocket(ApplicationProto): OP_CONT = 0x00 OP_TEXT = 0x01 -- cgit From de885feb0656fcce8f4a27d737e8507e57f4ab88 Mon Sep 17 00:00:00 2001 From: "Sergey A. Osokin" Date: Fri, 7 Jul 2023 09:54:23 -0400 Subject: Update third-party components for Unit's Java module. --- test/unit/applications/lang/java.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/applications') diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index f6f71b7d..a253aea5 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -53,7 +53,7 @@ class ApplicationJava(ApplicationProto): os.makedirs(classes_path) classpath = ( - f'{option.current_dir}/build/tomcat-servlet-api-9.0.70.jar' + f'{option.current_dir}/build/tomcat-servlet-api-9.0.75.jar' ) ws_jars = glob.glob( -- cgit