diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2023-06-14 18:20:09 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2023-06-14 18:20:09 +0100 |
commit | c183bd8749a19477390f8cb77efe5f6d223f0905 (patch) | |
tree | 4e821e9cb07be9a86bf2d442acb3ea6740ba5a99 /test/test_static_symlink.py | |
parent | c6d05191a069ac150cc8eb2bece75cf79c0a465a (diff) | |
download | unit-c183bd8749a19477390f8cb77efe5f6d223f0905.tar.gz unit-c183bd8749a19477390f8cb77efe5f6d223f0905.tar.bz2 |
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.
Diffstat (limited to '')
-rw-r--r-- | test/test_static_symlink.py | 134 |
1 files changed, 68 insertions, 66 deletions
diff --git a/test/test_static_symlink.py b/test/test_static_symlink.py index de65b85b..1f7d7907 100644 --- a/test/test_static_symlink.py +++ b/test/test_static_symlink.py @@ -2,92 +2,94 @@ import os from pathlib import Path import pytest -from unit.applications.proto import TestApplicationProto +from unit.applications.proto import ApplicationProto prerequisites = {'features': {'chroot': True}} +client = ApplicationProto() -class TestStaticSymlink(TestApplicationProto): - @pytest.fixture(autouse=True) - def setup_method_fixture(self, temp_dir): - os.makedirs(f'{temp_dir}/assets/dir/dir') - Path(f'{temp_dir}/assets/index.html').write_text('0123456789') - Path(f'{temp_dir}/assets/dir/file').write_text('blah') - self._load_conf( - { - "listeners": {"*:7080": {"pass": "routes"}}, - "routes": [{"action": {"share": f'{temp_dir}/assets$uri'}}], - } - ) +@pytest.fixture(autouse=True) +def setup_method_fixture(temp_dir): + os.makedirs(f'{temp_dir}/assets/dir/dir') + Path(f'{temp_dir}/assets/index.html').write_text('0123456789') + Path(f'{temp_dir}/assets/dir/file').write_text('blah') + + assert 'success' in client.conf( + { + "listeners": {"*:7080": {"pass": "routes"}}, + "routes": [{"action": {"share": f'{temp_dir}/assets$uri'}}], + } + ) + - def test_static_symlink(self, temp_dir, skip_alert): - skip_alert(r'opening.*failed') +def test_static_symlink(temp_dir, skip_alert): + skip_alert(r'opening.*failed') - os.symlink(f'{temp_dir}/assets/dir', f'{temp_dir}/assets/link') + os.symlink(f'{temp_dir}/assets/dir', f'{temp_dir}/assets/link') - assert self.get(url='/dir')['status'] == 301, 'dir' - assert self.get(url='/dir/file')['status'] == 200, 'file' - assert self.get(url='/link')['status'] == 301, 'symlink dir' - assert self.get(url='/link/file')['status'] == 200, 'symlink file' + assert client.get(url='/dir')['status'] == 301, 'dir' + assert client.get(url='/dir/file')['status'] == 200, 'file' + assert client.get(url='/link')['status'] == 301, 'symlink dir' + assert client.get(url='/link/file')['status'] == 200, 'symlink file' - assert 'success' in self.conf( - {"share": f'{temp_dir}/assets$uri', "follow_symlinks": False}, - 'routes/0/action', - ), 'configure symlink disable' + assert 'success' in client.conf( + {"share": f'{temp_dir}/assets$uri', "follow_symlinks": False}, + 'routes/0/action', + ), 'configure symlink disable' - assert self.get(url='/link/file')['status'] == 403, 'symlink disabled' + assert client.get(url='/link/file')['status'] == 403, 'symlink disabled' - assert 'success' in self.conf( - {"share": f'{temp_dir}/assets$uri', "follow_symlinks": True}, - 'routes/0/action', - ), 'configure symlink enable' + assert 'success' in client.conf( + {"share": f'{temp_dir}/assets$uri', "follow_symlinks": True}, + 'routes/0/action', + ), 'configure symlink enable' - assert self.get(url='/link/file')['status'] == 200, 'symlink enabled' + assert client.get(url='/link/file')['status'] == 200, 'symlink enabled' - def test_static_symlink_two_blocks(self, temp_dir, skip_alert): - skip_alert(r'opening.*failed') - os.symlink(f'{temp_dir}/assets/dir', f'{temp_dir}/assets/link') +def test_static_symlink_two_blocks(temp_dir, skip_alert): + skip_alert(r'opening.*failed') - assert 'success' in self.conf( - [ - { - "match": {"method": "HEAD"}, - "action": { - "share": f'{temp_dir}/assets$uri', - "follow_symlinks": False, - }, + os.symlink(f'{temp_dir}/assets/dir', f'{temp_dir}/assets/link') + + assert 'success' in client.conf( + [ + { + "match": {"method": "HEAD"}, + "action": { + "share": f'{temp_dir}/assets$uri', + "follow_symlinks": False, }, - { - "match": {"method": "GET"}, - "action": { - "share": f'{temp_dir}/assets$uri', - "follow_symlinks": True, - }, + }, + { + "match": {"method": "GET"}, + "action": { + "share": f'{temp_dir}/assets$uri', + "follow_symlinks": True, }, - ], - 'routes', - ), 'configure two options' + }, + ], + 'routes', + ), 'configure two options' - assert self.get(url='/link/file')['status'] == 200, 'block enabled' - assert self.head(url='/link/file')['status'] == 403, 'block disabled' + assert client.get(url='/link/file')['status'] == 200, 'block enabled' + assert client.head(url='/link/file')['status'] == 403, 'block disabled' - def test_static_symlink_chroot(self, temp_dir, skip_alert): - skip_alert(r'opening.*failed') - os.symlink( - f'{temp_dir}/assets/dir/file', f'{temp_dir}/assets/dir/dir/link' - ) +def test_static_symlink_chroot(temp_dir, skip_alert): + skip_alert(r'opening.*failed') - assert self.get(url='/dir/dir/link')['status'] == 200, 'default chroot' + os.symlink(f'{temp_dir}/assets/dir/file', f'{temp_dir}/assets/dir/dir/link') - assert 'success' in self.conf( - { - "share": f'{temp_dir}/assets$uri', - "chroot": f'{temp_dir}/assets/dir/dir', - }, - 'routes/0/action', - ), 'configure chroot' + assert client.get(url='/dir/dir/link')['status'] == 200, 'default chroot' + + assert 'success' in client.conf( + { + "share": f'{temp_dir}/assets$uri', + "chroot": f'{temp_dir}/assets/dir/dir', + }, + 'routes/0/action', + ), 'configure chroot' - assert self.get(url='/dir/dir/link')['status'] == 404, 'chroot' + assert client.get(url='/dir/dir/link')['status'] == 404, 'chroot' |