summaryrefslogtreecommitdiffhomepage
path: root/test/test_static_types.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2023-02-21 17:21:29 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2023-02-21 17:21:29 +0000
commit7934dcabbc3c2b585e8d3f8fcee7020ba26f1687 (patch)
treebd0861e7832c14d92dd0ed9753932e58a2daf818 /test/test_static_types.py
parentfcabbf09d85397e244f6486d6eca25e2366b61cd (diff)
downloadunit-7934dcabbc3c2b585e8d3f8fcee7020ba26f1687.tar.gz
unit-7934dcabbc3c2b585e8d3f8fcee7020ba26f1687.tar.bz2
Tests: switched to using f-strings.
Previously, it was necessary to support older versions of Python for compatibility. F-strings were released in Python 3.6. Python 3.5 was marked as unsupported by the end of 2020, so now it's possible to start using f-strings safely for better readability and performance.
Diffstat (limited to 'test/test_static_types.py')
-rw-r--r--test/test_static_types.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/test/test_static_types.py b/test/test_static_types.py
index 0e86517b..28ab28e6 100644
--- a/test/test_static_types.py
+++ b/test/test_static_types.py
@@ -9,11 +9,11 @@ class TestStaticTypes(TestApplicationProto):
@pytest.fixture(autouse=True)
def setup_method_fixture(self, temp_dir):
- Path(temp_dir + '/assets').mkdir()
+ Path(f'{temp_dir}/assets').mkdir()
for ext in ['.xml', '.mp4', '.php', '', '.txt', '.html', '.png']:
- Path(temp_dir + '/assets/file' + ext).write_text(ext)
+ Path(f'{temp_dir}/assets/file{ext}').write_text(ext)
- Path(temp_dir + '/assets/index.html').write_text('index')
+ Path(f'{temp_dir}/assets/index.html').write_text('index')
self._load_conf(
{
@@ -21,7 +21,7 @@ class TestStaticTypes(TestApplicationProto):
"*:7080": {"pass": "routes"},
"*:7081": {"pass": "routes"},
},
- "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
+ "routes": [{"action": {"share": f'{temp_dir}/assets$uri'}}],
"applications": {},
}
)
@@ -35,39 +35,39 @@ class TestStaticTypes(TestApplicationProto):
assert resp['body'] == body, 'body'
def test_static_types_basic(self, temp_dir):
- self.action_update({"share": temp_dir + "/assets$uri"})
+ self.action_update({"share": f'{temp_dir}/assets$uri'})
self.check_body('/index.html', 'index')
self.check_body('/file.xml', '.xml')
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": "application/xml"}
+ {"share": f'{temp_dir}/assets$uri', "types": "application/xml"}
)
self.check_body('/file.xml', '.xml')
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["application/xml"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["application/xml"]}
)
self.check_body('/file.xml', '.xml')
- self.action_update({"share": temp_dir + "/assets$uri", "types": [""]})
+ self.action_update({"share": f'{temp_dir}/assets$uri', "types": [""]})
assert self.get(url='/file.xml')['status'] == 403, 'no mtype'
def test_static_types_wildcard(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["application/*"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["application/*"]}
)
self.check_body('/file.xml', '.xml')
assert self.get(url='/file.mp4')['status'] == 403, 'app * mtype mp4'
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["video/*"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["video/*"]}
)
assert self.get(url='/file.xml')['status'] == 403, 'video * mtype xml'
self.check_body('/file.mp4', '.mp4')
def test_static_types_negation(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["!application/xml"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["!application/xml"]}
)
assert self.get(url='/file.xml')['status'] == 403, 'forbidden negation'
self.check_body('/file.mp4', '.mp4')
@@ -75,7 +75,7 @@ class TestStaticTypes(TestApplicationProto):
# sorting negation
self.action_update(
{
- "share": temp_dir + "/assets$uri",
+ "share": f'{temp_dir}/assets$uri',
"types": ["!video/*", "image/png", "!image/jpg"],
}
)
@@ -86,7 +86,7 @@ class TestStaticTypes(TestApplicationProto):
def test_static_types_regex(self, temp_dir):
self.action_update(
{
- "share": temp_dir + "/assets$uri",
+ "share": f'{temp_dir}/assets$uri',
"types": ["~text/(html|plain)"],
}
)
@@ -96,7 +96,7 @@ class TestStaticTypes(TestApplicationProto):
def test_static_types_case(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["!APpliCaTiOn/xMl"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["!APpliCaTiOn/xMl"]}
)
self.check_body('/file.mp4', '.mp4')
assert (
@@ -104,7 +104,7 @@ class TestStaticTypes(TestApplicationProto):
), 'mixed case xml negation'
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["vIdEo/mp4"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["vIdEo/mp4"]}
)
assert self.get(url='/file.mp4')['status'] == 200, 'mixed case'
assert (
@@ -112,7 +112,7 @@ class TestStaticTypes(TestApplicationProto):
), 'mixed case video negation'
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["vIdEo/*"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["vIdEo/*"]}
)
self.check_body('/file.mp4', '.mp4')
assert (
@@ -128,7 +128,7 @@ class TestStaticTypes(TestApplicationProto):
},
{
"action": {
- "share": temp_dir + "/assets$uri",
+ "share": f'{temp_dir}/assets$uri',
"types": ["!application/x-httpd-php"],
"fallback": {"proxy": "http://127.0.0.1:7081"},
}
@@ -142,7 +142,7 @@ class TestStaticTypes(TestApplicationProto):
def test_static_types_index(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": "application/xml"}
+ {"share": f'{temp_dir}/assets$uri', "types": "application/xml"}
)
self.check_body('/', 'index')
self.check_body('/file.xml', '.xml')
@@ -153,7 +153,7 @@ class TestStaticTypes(TestApplicationProto):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
+ "routes": [{"action": {"share": f'{temp_dir}/assets$uri'}}],
"applications": {},
"settings": {
"http": {
@@ -163,10 +163,10 @@ class TestStaticTypes(TestApplicationProto):
}
)
- self.action_update({"share": temp_dir + "/assets$uri", "types": [""]})
+ self.action_update({"share": f'{temp_dir}/assets$uri', "types": [""]})
assert self.get(url='/file')['status'] == 403, 'forbidden custom mime'
self.action_update(
- {"share": temp_dir + "/assets$uri", "types": ["test/mime-type"]}
+ {"share": f'{temp_dir}/assets$uri', "types": ["test/mime-type"]}
)
self.check_body('/file', '')