summaryrefslogtreecommitdiffhomepage
path: root/test/test_static_share.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2023-06-14 18:20:09 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2023-06-14 18:20:09 +0100
commitc183bd8749a19477390f8cb77efe5f6d223f0905 (patch)
tree4e821e9cb07be9a86bf2d442acb3ea6740ba5a99 /test/test_static_share.py
parentc6d05191a069ac150cc8eb2bece75cf79c0a465a (diff)
downloadunit-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 'test/test_static_share.py')
-rw-r--r--test/test_static_share.py135
1 files changed, 69 insertions, 66 deletions
diff --git a/test/test_static_share.py b/test/test_static_share.py
index 2eb63659..ac5afb50 100644
--- a/test/test_static_share.py
+++ b/test/test_static_share.py
@@ -2,69 +2,72 @@ import os
from pathlib import Path
import pytest
-from unit.applications.proto import TestApplicationProto
-
-
-class TestStaticShare(TestApplicationProto):
- @pytest.fixture(autouse=True)
- def setup_method_fixture(self, temp_dir):
- os.makedirs(f'{temp_dir}/assets/dir')
- os.makedirs(f'{temp_dir}/assets/dir2')
-
- Path(f'{temp_dir}/assets/dir/file').write_text('1')
- Path(f'{temp_dir}/assets/dir2/file2').write_text('2')
-
- assert 'success' in self.conf(
- {
- "listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": f'{temp_dir}/assets$uri'}}],
- "applications": {},
- }
- )
-
- def action_update(self, conf):
- assert 'success' in self.conf(conf, 'routes/0/action')
-
- def test_share_array(self, temp_dir):
- assert self.get(url='/dir/file')['body'] == '1'
- assert self.get(url='/dir2/file2')['body'] == '2'
-
- self.action_update({"share": [f'{temp_dir}/assets/dir$uri']})
-
- assert self.get(url='/file')['body'] == '1'
- assert self.get(url='/file2')['status'] == 404
-
- self.action_update(
- {
- "share": [
- f'{temp_dir}/assets/dir$uri',
- f'{temp_dir}/assets/dir2$uri',
- ]
- }
- )
-
- assert self.get(url='/file')['body'] == '1'
- assert self.get(url='/file2')['body'] == '2'
-
- self.action_update(
- {
- "share": [
- f'{temp_dir}/assets/dir2$uri',
- f'{temp_dir}/assets/dir3$uri',
- ]
- }
- )
-
- assert self.get(url='/file')['status'] == 404
- assert self.get(url='/file2')['body'] == '2'
-
- def test_share_array_fallback(self):
- self.action_update(
- {"share": ["/blah", "/blah2"], "fallback": {"return": 201}}
- )
-
- assert self.get()['status'] == 201
-
- def test_share_array_invalid(self):
- assert 'error' in self.conf({"share": []}, 'routes/0/action')
- assert 'error' in self.conf({"share": {}}, 'routes/0/action')
+from unit.applications.proto import ApplicationProto
+
+client = ApplicationProto()
+
+
+@pytest.fixture(autouse=True)
+def setup_method_fixture(temp_dir):
+ os.makedirs(f'{temp_dir}/assets/dir')
+ os.makedirs(f'{temp_dir}/assets/dir2')
+
+ Path(f'{temp_dir}/assets/dir/file').write_text('1')
+ Path(f'{temp_dir}/assets/dir2/file2').write_text('2')
+
+ assert 'success' in client.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes"}},
+ "routes": [{"action": {"share": f'{temp_dir}/assets$uri'}}],
+ "applications": {},
+ }
+ )
+
+
+def action_update(conf):
+ assert 'success' in client.conf(conf, 'routes/0/action')
+
+
+def test_share_array(temp_dir):
+ assert client.get(url='/dir/file')['body'] == '1'
+ assert client.get(url='/dir2/file2')['body'] == '2'
+
+ action_update({"share": [f'{temp_dir}/assets/dir$uri']})
+
+ assert client.get(url='/file')['body'] == '1'
+ assert client.get(url='/file2')['status'] == 404
+
+ action_update(
+ {
+ "share": [
+ f'{temp_dir}/assets/dir$uri',
+ f'{temp_dir}/assets/dir2$uri',
+ ]
+ }
+ )
+
+ assert client.get(url='/file')['body'] == '1'
+ assert client.get(url='/file2')['body'] == '2'
+
+ action_update(
+ {
+ "share": [
+ f'{temp_dir}/assets/dir2$uri',
+ f'{temp_dir}/assets/dir3$uri',
+ ]
+ }
+ )
+
+ assert client.get(url='/file')['status'] == 404
+ assert client.get(url='/file2')['body'] == '2'
+
+
+def test_share_array_fallback():
+ action_update({"share": ["/blah", "/blah2"], "fallback": {"return": 201}})
+
+ assert client.get()['status'] == 201
+
+
+def test_share_array_invalid():
+ assert 'error' in client.conf({"share": []}, 'routes/0/action')
+ assert 'error' in client.conf({"share": {}}, 'routes/0/action')