summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2021-06-28 22:05:40 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2021-06-28 22:05:40 +0100
commitb86891c4ef848a2da05abd1350af5f0b8e4335fa (patch)
tree38dccefa03558d95014a2fd14a6d8cc85e380473
parent72420358be128640dd09a0914a8d88b50c152545 (diff)
downloadunit-b86891c4ef848a2da05abd1350af5f0b8e4335fa.tar.gz
unit-b86891c4ef848a2da05abd1350af5f0b8e4335fa.tar.bz2
Tests: renamed share to static.
Also minor style changes.
Diffstat (limited to '')
-rw-r--r--test/conftest.py2
-rw-r--r--test/test_configuration.py3
-rw-r--r--test/test_node_es_modules.py3
-rw-r--r--test/test_static_chroot.py (renamed from test/test_share_chroot.py)19
-rw-r--r--test/test_static_fallback.py (renamed from test/test_share_fallback.py)37
-rw-r--r--test/test_static_mount.py (renamed from test/test_share_mount.py)18
-rw-r--r--test/test_static_symlink.py (renamed from test/test_share_symlink.py)16
-rw-r--r--test/test_static_types.py (renamed from test/test_share_types.py)21
8 files changed, 57 insertions, 62 deletions
diff --git a/test/conftest.py b/test/conftest.py
index 5ea4e49d..db34984f 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -22,8 +22,8 @@ from unit.check.node import check_node
from unit.check.regex import check_regex
from unit.check.tls import check_openssl
from unit.http import TestHTTP
-from unit.option import option
from unit.log import Log
+from unit.option import option
from unit.utils import public_dir
from unit.utils import waitforfiles
diff --git a/test/test_configuration.py b/test/test_configuration.py
index 880aef6c..c149658c 100644
--- a/test/test_configuration.py
+++ b/test/test_configuration.py
@@ -1,6 +1,7 @@
+import socket
+
import pytest
-import socket
from unit.control import TestControl
diff --git a/test/test_node_es_modules.py b/test/test_node_es_modules.py
index 0945a967..5464d4a6 100644
--- a/test/test_node_es_modules.py
+++ b/test/test_node_es_modules.py
@@ -1,6 +1,7 @@
+from distutils.version import LooseVersion
+
import pytest
-from distutils.version import LooseVersion
from unit.applications.lang.node import TestApplicationNode
from unit.applications.websockets import TestApplicationWebsocket
diff --git a/test/test_share_chroot.py b/test/test_static_chroot.py
index 02b3657d..f9bc93a8 100644
--- a/test/test_share_chroot.py
+++ b/test/test_static_chroot.py
@@ -6,17 +6,14 @@ import pytest
from unit.applications.proto import TestApplicationProto
-class TestShareChroot(TestApplicationProto):
+class TestStaticChroot(TestApplicationProto):
prerequisites = {'features': ['chroot']}
@pytest.fixture(autouse=True)
def setup_method_fixture(self, temp_dir):
os.makedirs(temp_dir + '/assets/dir')
- with open(temp_dir + '/assets/index.html', 'w') as index, open(
- temp_dir + '/assets/dir/file', 'w'
- ) as file:
- index.write('0123456789')
- file.write('blah')
+ Path(temp_dir + '/assets/index.html').write_text('0123456789')
+ Path(temp_dir + '/assets/dir/file').write_text('blah')
test = Path(__file__)
self.test_path = '/' + test.parent.name + '/' + test.name
@@ -28,7 +25,7 @@ class TestShareChroot(TestApplicationProto):
}
)
- def test_share_chroot(self, temp_dir):
+ def test_static_chroot(self, temp_dir):
assert self.get(url='/dir/file')['status'] == 200, 'default chroot'
assert self.get(url='/index.html')['status'] == 200, 'default chroot 2'
@@ -44,7 +41,7 @@ class TestShareChroot(TestApplicationProto):
assert self.get(url='/index.html')['status'] == 403, 'chroot 403 2'
assert self.get(url='/file')['status'] == 403, 'chroot 403'
- def test_share_chroot_permission(self, is_su, temp_dir):
+ def test_static_chroot_permission(self, is_su, temp_dir):
if is_su:
pytest.skip('does\'t work under root')
@@ -60,7 +57,7 @@ class TestShareChroot(TestApplicationProto):
assert self.get(url='/dir/file')['status'] == 200, 'chroot'
- def test_share_chroot_empty(self, temp_dir):
+ def test_static_chroot_empty(self, temp_dir):
assert 'success' in self.conf(
{"share": temp_dir + "/assets", "chroot": ""}, 'routes/0/action',
), 'configure chroot empty absolute'
@@ -77,7 +74,7 @@ class TestShareChroot(TestApplicationProto):
self.get(url=self.test_path)['status'] == 200
), 'chroot empty relative'
- def test_share_chroot_relative(self, is_su, temp_dir):
+ def test_static_chroot_relative(self, is_su, temp_dir):
if is_su:
pytest.skip('does\'t work under root')
@@ -99,7 +96,7 @@ class TestShareChroot(TestApplicationProto):
assert self.get(url=self.test_path)['status'] == 200, 'relative'
- def test_share_chroot_invalid(self, temp_dir):
+ def test_static_chroot_invalid(self, temp_dir):
assert 'error' in self.conf(
{"share": temp_dir, "chroot": True}, 'routes/0/action',
), 'configure chroot error'
diff --git a/test/test_share_fallback.py b/test/test_static_fallback.py
index 0b1c270e..dc9056b9 100644
--- a/test/test_share_fallback.py
+++ b/test/test_static_fallback.py
@@ -1,21 +1,21 @@
import os
+from pathlib import Path
import pytest
from unit.applications.proto import TestApplicationProto
-from unit.option import option
-class TestStatic(TestApplicationProto):
+class TestStaticFallback(TestApplicationProto):
prerequisites = {}
- def setup_method(self):
- os.makedirs(option.temp_dir + '/assets/dir')
- with open(option.temp_dir + '/assets/index.html', 'w') as index:
- index.write('0123456789')
+ @pytest.fixture(autouse=True)
+ def setup_method_fixture(self, temp_dir):
+ os.makedirs(temp_dir + '/assets/dir')
+ Path(temp_dir + '/assets/index.html').write_text('0123456789')
- os.makedirs(option.temp_dir + '/assets/403')
- os.chmod(option.temp_dir + '/assets/403', 0o000)
+ os.makedirs(temp_dir + '/assets/403')
+ os.chmod(temp_dir + '/assets/403', 0o000)
self._load_conf(
{
@@ -23,21 +23,22 @@ class TestStatic(TestApplicationProto):
"*:7080": {"pass": "routes"},
"*:7081": {"pass": "routes"},
},
- "routes": [{"action": {"share": option.temp_dir + "/assets"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets"}}],
"applications": {},
}
)
- def teardown_method(self):
+ yield
+
try:
- os.chmod(option.temp_dir + '/assets/403', 0o777)
+ os.chmod(temp_dir + '/assets/403', 0o777)
except FileNotFoundError:
pass
def action_update(self, conf):
assert 'success' in self.conf(conf, 'routes/0/action')
- def test_fallback(self):
+ def test_static_fallback(self):
self.action_update({"share": "/blah"})
assert self.get()['status'] == 404, 'bad path no fallback'
@@ -47,7 +48,7 @@ class TestStatic(TestApplicationProto):
assert resp['status'] == 200, 'bad path fallback status'
assert resp['body'] == '', 'bad path fallback'
- def test_fallback_valid_path(self, temp_dir):
+ def test_static_fallback_valid_path(self, temp_dir):
self.action_update(
{"share": temp_dir + "/assets", "fallback": {"return": 200}}
)
@@ -65,7 +66,7 @@ class TestStatic(TestApplicationProto):
assert self.get(url='/dir')['status'] == 301, 'fallback status 301'
- def test_fallback_nested(self):
+ def test_static_fallback_nested(self):
self.action_update(
{
"share": "/blah",
@@ -80,7 +81,7 @@ class TestStatic(TestApplicationProto):
assert resp['status'] == 200, 'fallback nested status'
assert resp['body'] == '', 'fallback nested'
- def test_fallback_share(self, temp_dir):
+ def test_static_fallback_share(self, temp_dir):
self.action_update(
{"share": "/blah", "fallback": {"share": temp_dir + "/assets"},}
)
@@ -97,7 +98,7 @@ class TestStatic(TestApplicationProto):
self.get(url='/dir')['status'] == 301
), 'fallback share status 301'
- def test_fallback_proxy(self):
+ def test_static_fallback_proxy(self):
assert 'success' in self.conf(
[
{
@@ -119,7 +120,7 @@ class TestStatic(TestApplicationProto):
assert resp['body'] == '', 'fallback proxy'
@pytest.mark.skip('not yet')
- def test_fallback_proxy_loop(self, skip_alert):
+ def test_static_fallback_proxy_loop(self, skip_alert):
skip_alert(
r'open.*/blah/index.html.*failed',
r'accept.*failed',
@@ -135,7 +136,7 @@ class TestStatic(TestApplicationProto):
assert 'success' in self.conf_delete('listeners/*:7081')
self.get(read_timeout=1)
- def test_fallback_invalid(self):
+ def test_static_fallback_invalid(self):
def check_error(conf):
assert 'error' in self.conf(conf, 'routes/0/action')
diff --git a/test/test_share_mount.py b/test/test_static_mount.py
index f22fbe75..570f6439 100644
--- a/test/test_share_mount.py
+++ b/test/test_static_mount.py
@@ -1,12 +1,13 @@
import os
import subprocess
+from pathlib import Path
import pytest
from unit.applications.proto import TestApplicationProto
-class TestShareMount(TestApplicationProto):
+class TestStaticMount(TestApplicationProto):
prerequisites = {'features': ['chroot']}
@pytest.fixture(autouse=True)
@@ -17,12 +18,9 @@ class TestShareMount(TestApplicationProto):
os.makedirs(temp_dir + '/assets/dir/mount')
os.makedirs(temp_dir + '/assets/dir/dir')
os.makedirs(temp_dir + '/assets/mount')
- with open(temp_dir + '/assets/index.html', 'w') as index, open(
- temp_dir + '/assets/dir/dir/file', 'w'
- ) as file, open(temp_dir + '/assets/mount/index.html', 'w') as mount:
- index.write('index')
- file.write('file')
- mount.write('mount')
+ Path(temp_dir + '/assets/index.html').write_text('index')
+ Path(temp_dir + '/assets/dir/dir/file').write_text('file')
+ Path(temp_dir + '/assets/mount/index.html').write_text('mount')
try:
process = subprocess.Popen(
@@ -66,7 +64,7 @@ class TestShareMount(TestApplicationProto):
except:
pytest.fail('Can\'t run umount process.')
- def test_share_mount(self, temp_dir, skip_alert):
+ def test_static_mount(self, temp_dir, skip_alert):
skip_alert(r'opening.*failed')
resp = self.get(url='/mount/')
@@ -89,7 +87,7 @@ class TestShareMount(TestApplicationProto):
assert resp['status'] == 200
assert resp['body'] == 'mount'
- def test_share_mount_two_blocks(self, temp_dir, skip_alert):
+ def test_static_mount_two_blocks(self, temp_dir, skip_alert):
skip_alert(r'opening.*failed')
os.symlink(temp_dir + '/assets/dir', temp_dir + '/assets/link')
@@ -117,7 +115,7 @@ class TestShareMount(TestApplicationProto):
assert self.get(url='/mount/')['status'] == 200, 'block enabled'
assert self.head(url='/mount/')['status'] == 403, 'block disabled'
- def test_share_mount_chroot(self, temp_dir, skip_alert):
+ def test_static_mount_chroot(self, temp_dir, skip_alert):
skip_alert(r'opening.*failed')
assert 'success' in self.conf(
diff --git a/test/test_share_symlink.py b/test/test_static_symlink.py
index 3970b605..35eb402a 100644
--- a/test/test_share_symlink.py
+++ b/test/test_static_symlink.py
@@ -1,21 +1,19 @@
import os
+from pathlib import Path
import pytest
from unit.applications.proto import TestApplicationProto
-class TestShareSymlink(TestApplicationProto):
+class TestStaticSymlink(TestApplicationProto):
prerequisites = {'features': ['chroot']}
@pytest.fixture(autouse=True)
def setup_method_fixture(self, temp_dir):
os.makedirs(temp_dir + '/assets/dir/dir')
- with open(temp_dir + '/assets/index.html', 'w') as index, open(
- temp_dir + '/assets/dir/file', 'w'
- ) as file:
- index.write('0123456789')
- file.write('blah')
+ Path(temp_dir + '/assets/index.html').write_text('0123456789')
+ Path(temp_dir + '/assets/dir/file').write_text('blah')
self._load_conf(
{
@@ -24,7 +22,7 @@ class TestShareSymlink(TestApplicationProto):
}
)
- def test_share_symlink(self, temp_dir, skip_alert):
+ def test_static_symlink(self, temp_dir, skip_alert):
skip_alert(r'opening.*failed')
os.symlink(temp_dir + '/assets/dir', temp_dir + '/assets/link')
@@ -48,7 +46,7 @@ class TestShareSymlink(TestApplicationProto):
assert self.get(url='/link/file')['status'] == 200, 'symlink enabled'
- def test_share_symlink_two_blocks(self, temp_dir, skip_alert):
+ def test_static_symlink_two_blocks(self, temp_dir, skip_alert):
skip_alert(r'opening.*failed')
os.symlink(temp_dir + '/assets/dir', temp_dir + '/assets/link')
@@ -76,7 +74,7 @@ class TestShareSymlink(TestApplicationProto):
assert self.get(url='/link/file')['status'] == 200, 'block enabled'
assert self.head(url='/link/file')['status'] == 403, 'block disabled'
- def test_share_symlink_chroot(self, temp_dir, skip_alert):
+ def test_static_symlink_chroot(self, temp_dir, skip_alert):
skip_alert(r'opening.*failed')
os.symlink(
diff --git a/test/test_share_types.py b/test/test_static_types.py
index b5ed97a0..20defddf 100644
--- a/test/test_share_types.py
+++ b/test/test_static_types.py
@@ -1,12 +1,11 @@
-import os
from pathlib import Path
import pytest
+
from unit.applications.proto import TestApplicationProto
-from unit.option import option
-class TestShareTypes(TestApplicationProto):
+class TestStaticTypes(TestApplicationProto):
prerequisites = {}
@pytest.fixture(autouse=True)
@@ -36,7 +35,7 @@ class TestShareTypes(TestApplicationProto):
assert resp['status'] == 200, 'status'
assert resp['body'] == body, 'body'
- def test_share_types_basic(self, temp_dir):
+ def test_static_types_basic(self, temp_dir):
self.action_update({"share": temp_dir + "/assets"})
self.check_body('/index.html', 'index')
self.check_body('/file.xml', '.xml')
@@ -54,7 +53,7 @@ class TestShareTypes(TestApplicationProto):
self.action_update({"share": temp_dir + "/assets", "types": [""]})
assert self.get(url='/file.xml')['status'] == 403, 'no mtype'
- def test_share_types_wildcard(self, temp_dir):
+ def test_static_types_wildcard(self, temp_dir):
self.action_update(
{"share": temp_dir + "/assets", "types": ["application/*"]}
)
@@ -67,7 +66,7 @@ class TestShareTypes(TestApplicationProto):
assert self.get(url='/file.xml')['status'] == 403, 'video * mtype xml'
self.check_body('/file.mp4', '.mp4')
- def test_share_types_negation(self, temp_dir):
+ def test_static_types_negation(self, temp_dir):
self.action_update(
{"share": temp_dir + "/assets", "types": ["!application/xml"]}
)
@@ -85,7 +84,7 @@ class TestShareTypes(TestApplicationProto):
self.check_body('/file.png', '.png')
assert self.get(url='/file.jpg')['status'] == 403, 'negation sort jpg'
- def test_share_types_regex(self, temp_dir):
+ def test_static_types_regex(self, temp_dir):
self.action_update(
{"share": temp_dir + "/assets", "types": ["~text/(html|plain)"]}
)
@@ -93,7 +92,7 @@ class TestShareTypes(TestApplicationProto):
self.check_body('/file.html', '.html')
self.check_body('/file.txt', '.txt')
- def test_share_types_case(self, temp_dir):
+ def test_static_types_case(self, temp_dir):
self.action_update(
{"share": temp_dir + "/assets", "types": ["!APpliCaTiOn/xMl"]}
)
@@ -118,7 +117,7 @@ class TestShareTypes(TestApplicationProto):
self.get(url='/file.xml')['status'] == 403
), 'mixed case video * negation'
- def test_share_types_fallback(self, temp_dir):
+ def test_static_types_fallback(self, temp_dir):
assert 'success' in self.conf(
[
{
@@ -139,7 +138,7 @@ class TestShareTypes(TestApplicationProto):
self.check_body('/file.php', '')
self.check_body('/file.mp4', '.mp4')
- def test_share_types_index(self, temp_dir):
+ def test_static_types_index(self, temp_dir):
self.action_update(
{"share": temp_dir + "/assets", "types": "application/xml"}
)
@@ -147,7 +146,7 @@ class TestShareTypes(TestApplicationProto):
self.check_body('/file.xml', '.xml')
assert self.get(url='/file.mp4')['status'] == 403, 'forbidden mtype'
- def test_share_types_custom_mime(self, temp_dir):
+ def test_static_types_custom_mime(self, temp_dir):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},