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_python_environment.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 'test/test_python_environment.py')
-rw-r--r-- | test/test_python_environment.py | 295 |
1 files changed, 151 insertions, 144 deletions
diff --git a/test/test_python_environment.py b/test/test_python_environment.py index a57e3760..6aa02c94 100644 --- a/test/test_python_environment.py +++ b/test/test_python_environment.py @@ -1,155 +1,162 @@ -from unit.applications.lang.python import TestApplicationPython +from unit.applications.lang.python import ApplicationPython prerequisites = {'modules': {'python': 'any'}} +client = ApplicationPython() -class TestPythonEnvironment(TestApplicationPython): - def test_python_environment_name_null(self): - self.load('environment') - - assert 'error' in self.conf( - {"va\0r": "val1"}, 'applications/environment/environment' - ), 'name null' - - def test_python_environment_name_equals(self): - self.load('environment') - - assert 'error' in self.conf( - {"var=": "val1"}, 'applications/environment/environment' - ), 'name equals' - - def test_python_environment_value_null(self): - self.load('environment') - - assert 'error' in self.conf( - {"var": "\0val"}, 'applications/environment/environment' - ), 'value null' - - def test_python_environment_update(self): - self.load('environment') - - self.conf({"var": "val1"}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'var', - 'Connection': 'close', - } - )['body'] - == 'val1' - ), 'set' - - self.conf({"var": "val2"}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'var', - 'Connection': 'close', - } - )['body'] - == 'val2' - ), 'update' - - def test_python_environment_replace(self): - self.load('environment') - - self.conf({"var1": "val1"}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'var1', - 'Connection': 'close', - } - )['body'] - == 'val1' - ), 'set' - - self.conf({"var2": "val2"}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'var1,var2', - 'Connection': 'close', - } - )['body'] - == 'val2' - ), 'replace' - - def test_python_environment_clear(self): - self.load('environment') - - self.conf( - {"var1": "val1", "var2": "val2"}, - 'applications/environment/environment', - ) - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'var1,var2', - 'Connection': 'close', - } - )['body'] - == 'val1,val2' - ), 'set' - - self.conf({}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'var1,var2', - 'Connection': 'close', - } - )['body'] - == '' - ), 'clear' - - def test_python_environment_replace_default(self): - self.load('environment') - - home_default = self.get( + +def test_python_environment_name_null(): + client.load('environment') + + assert 'error' in client.conf( + {"va\0r": "val1"}, 'applications/environment/environment' + ), 'name null' + + +def test_python_environment_name_equals(): + client.load('environment') + + assert 'error' in client.conf( + {"var=": "val1"}, 'applications/environment/environment' + ), 'name equals' + + +def test_python_environment_value_null(): + client.load('environment') + + assert 'error' in client.conf( + {"var": "\0val"}, 'applications/environment/environment' + ), 'value null' + + +def test_python_environment_update(): + client.load('environment') + + client.conf({"var": "val1"}, 'applications/environment/environment') + + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'var', + 'Connection': 'close', + } + )['body'] + == 'val1' + ), 'set' + + client.conf({"var": "val2"}, 'applications/environment/environment') + + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'var', + 'Connection': 'close', + } + )['body'] + == 'val2' + ), 'update' + + +def test_python_environment_replace(): + client.load('environment') + + client.conf({"var1": "val1"}, 'applications/environment/environment') + + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'var1', + 'Connection': 'close', + } + )['body'] + == 'val1' + ), 'set' + + client.conf({"var2": "val2"}, 'applications/environment/environment') + + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'var1,var2', + 'Connection': 'close', + } + )['body'] + == 'val2' + ), 'replace' + + +def test_python_environment_clear(): + client.load('environment') + + client.conf( + {"var1": "val1", "var2": "val2"}, + 'applications/environment/environment', + ) + + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'var1,var2', + 'Connection': 'close', + } + )['body'] + == 'val1,val2' + ), 'set' + + client.conf({}, 'applications/environment/environment') + + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'var1,var2', + 'Connection': 'close', + } + )['body'] + == '' + ), 'clear' + + +def test_python_environment_replace_default(): + client.load('environment') + + home_default = client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'HOME', + 'Connection': 'close', + } + )['body'] + + assert len(home_default) > 1, 'get default' + + client.conf({"HOME": "/"}, 'applications/environment/environment') + + assert ( + client.get( headers={ 'Host': 'localhost', 'X-Variables': 'HOME', 'Connection': 'close', } )['body'] + == '/' + ), 'replace default' + + client.conf({}, 'applications/environment/environment') - assert len(home_default) > 1, 'get default' - - self.conf({"HOME": "/"}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'HOME', - 'Connection': 'close', - } - )['body'] - == '/' - ), 'replace default' - - self.conf({}, 'applications/environment/environment') - - assert ( - self.get( - headers={ - 'Host': 'localhost', - 'X-Variables': 'HOME', - 'Connection': 'close', - } - )['body'] - == home_default - ), 'restore default' + assert ( + client.get( + headers={ + 'Host': 'localhost', + 'X-Variables': 'HOME', + 'Connection': 'close', + } + )['body'] + == home_default + ), 'restore default' |