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.
This commit is contained in:
@@ -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}"}},
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}'
|
||||
|
||||
@@ -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}'
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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 []
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
|
||||
from unit.http import TestHTTP
|
||||
from unit.http import HTTP1
|
||||
from unit.option import option
|
||||
|
||||
http = TestHTTP()
|
||||
http = HTTP1()
|
||||
|
||||
|
||||
def check_chroot():
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from unit.applications.lang.go import TestApplicationGo
|
||||
from unit.applications.lang.go import ApplicationGo
|
||||
|
||||
|
||||
def check_go():
|
||||
return TestApplicationGo.prepare_env('empty') is not None
|
||||
return ApplicationGo.prepare_env('empty') is not None
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from unit.applications.lang.go import TestApplicationGo
|
||||
from unit.applications.lang.java import TestApplicationJava
|
||||
from unit.applications.lang.node import TestApplicationNode
|
||||
from unit.applications.lang.ruby import TestApplicationRuby
|
||||
from unit.http import TestHTTP
|
||||
from unit.applications.lang.go import ApplicationGo
|
||||
from unit.applications.lang.java import ApplicationJava
|
||||
from unit.applications.lang.node import ApplicationNode
|
||||
from unit.applications.lang.ruby import ApplicationRuby
|
||||
from unit.http import HTTP1
|
||||
from unit.option import option
|
||||
from unit.utils import getns
|
||||
|
||||
allns = ['pid', 'mnt', 'ipc', 'uts', 'cgroup', 'net']
|
||||
http = TestHTTP()
|
||||
http = HTTP1()
|
||||
|
||||
|
||||
def check_isolation():
|
||||
@@ -18,7 +18,7 @@ def check_isolation():
|
||||
|
||||
conf = ''
|
||||
if 'go' in available['modules']:
|
||||
TestApplicationGo().prepare_env('empty', 'app')
|
||||
ApplicationGo().prepare_env('empty', 'app')
|
||||
|
||||
conf = {
|
||||
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||
@@ -64,7 +64,7 @@ def check_isolation():
|
||||
}
|
||||
|
||||
elif 'ruby' in available['modules']:
|
||||
TestApplicationRuby().prepare_env('empty')
|
||||
ApplicationRuby().prepare_env('empty')
|
||||
|
||||
conf = {
|
||||
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||
@@ -80,7 +80,7 @@ def check_isolation():
|
||||
}
|
||||
|
||||
elif 'java' in available['modules']:
|
||||
TestApplicationJava().prepare_env('empty')
|
||||
ApplicationJava().prepare_env('empty')
|
||||
|
||||
conf = {
|
||||
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||
@@ -97,7 +97,7 @@ def check_isolation():
|
||||
}
|
||||
|
||||
elif 'node' in available['modules']:
|
||||
TestApplicationNode().prepare_env('basic')
|
||||
ApplicationNode().prepare_env('basic')
|
||||
|
||||
conf = {
|
||||
"listeners": {"*:7080": {"pass": "applications/basic"}},
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
|
||||
from unit.http import TestHTTP
|
||||
from unit.http import HTTP1
|
||||
from unit.option import option
|
||||
|
||||
http = TestHTTP()
|
||||
http = HTTP1()
|
||||
|
||||
|
||||
def check_unix_abstract():
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
|
||||
from unit.http import TestHTTP
|
||||
from unit.http import HTTP1
|
||||
from unit.option import option
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ def args_handler(conf_func):
|
||||
return args_wrapper
|
||||
|
||||
|
||||
class TestControl(TestHTTP):
|
||||
class Control(HTTP1):
|
||||
@args_handler
|
||||
def conf(self, conf, url):
|
||||
return self.put(**self._get_args(url, conf))['body']
|
||||
|
||||
@@ -10,7 +10,7 @@ import pytest
|
||||
from unit.option import option
|
||||
|
||||
|
||||
class TestHTTP:
|
||||
class HTTP1:
|
||||
def http(self, start_str, **kwargs):
|
||||
sock_type = kwargs.get('sock_type', 'ipv4')
|
||||
port = kwargs.get('port', 7080)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import platform
|
||||
|
||||
|
||||
class Options:
|
||||
_options = {
|
||||
'architecture': platform.architecture()[0],
|
||||
@@ -8,7 +9,7 @@ class Options:
|
||||
'is_privileged': os.geteuid() == 0,
|
||||
'skip_alerts': [],
|
||||
'skip_sanitizer': False,
|
||||
'system': platform.system()
|
||||
'system': platform.system(),
|
||||
}
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from unit.control import TestControl
|
||||
from unit.control import Control
|
||||
|
||||
|
||||
class Status:
|
||||
_status = None
|
||||
control = TestControl()
|
||||
control = Control()
|
||||
|
||||
def _check_zeros():
|
||||
assert Status.control.conf_get('/status') == {
|
||||
|
||||
Reference in New Issue
Block a user