summaryrefslogtreecommitdiffhomepage
path: root/test/test_php_isolation.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-09-16 21:31:15 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2020-09-16 21:31:15 +0100
commitd5e915934066c77a59d211efafca10c117b73d05 (patch)
treef894a3c09bd8aa43e87276eed377eb09f97e46fe /test/test_php_isolation.py
parent77ecb6ab49257dd662aa9c461fed3dc1d74e5092 (diff)
downloadunit-d5e915934066c77a59d211efafca10c117b73d05.tar.gz
unit-d5e915934066c77a59d211efafca10c117b73d05.tar.bz2
Tests: migrated to the pytest.
Diffstat (limited to '')
-rw-r--r--test/test_php_isolation.py154
1 files changed, 56 insertions, 98 deletions
diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py
index 3004a7b8..f4170f1b 100644
--- a/test/test_php_isolation.py
+++ b/test/test_php_isolation.py
@@ -1,7 +1,8 @@
-import unittest
+import pytest
from unit.applications.lang.php import TestApplicationPHP
from unit.feature.isolation import TestFeatureIsolation
+from conftest import option
class TestPHPIsolation(TestApplicationPHP):
@@ -10,171 +11,128 @@ class TestPHPIsolation(TestApplicationPHP):
isolation = TestFeatureIsolation()
@classmethod
- def setUpClass(cls, complete_check=True):
- unit = super().setUpClass(complete_check=False)
+ def setup_class(cls, complete_check=True):
+ unit = super().setup_class(complete_check=False)
- TestFeatureIsolation().check(cls.available, unit.testdir)
+ TestFeatureIsolation().check(cls.available, unit.temp_dir)
return unit if not complete_check else unit.complete()
- def test_php_isolation_rootfs(self):
+ def test_php_isolation_rootfs(self, is_su):
isolation_features = self.available['features']['isolation'].keys()
if 'mnt' not in isolation_features:
- print('requires mnt ns')
- raise unittest.SkipTest()
+ pytest.skip('requires mnt ns')
- if not self.is_su:
+ if not is_su:
if 'user' not in isolation_features:
- print('requires unprivileged userns or root')
- raise unittest.SkipTest()
+ pytest.skip('requires unprivileged userns or root')
if not 'unprivileged_userns_clone' in isolation_features:
- print('requires unprivileged userns or root')
- raise unittest.SkipTest()
+ pytest.skip('requires unprivileged userns or root')
isolation = {
- 'namespaces': {'credential': not self.is_su, 'mount': True},
- 'rootfs': self.current_dir,
+ 'namespaces': {'credential': not is_su, 'mount': True},
+ 'rootfs': option.test_dir,
}
self.load('phpinfo', isolation=isolation)
- self.assertIn(
- 'success', self.conf('"/php/phpinfo"', 'applications/phpinfo/root')
+ assert 'success' in self.conf(
+ '"/php/phpinfo"', 'applications/phpinfo/root'
)
- self.assertIn(
- 'success',
- self.conf(
- '"/php/phpinfo"', 'applications/phpinfo/working_directory'
- ),
+ assert 'success' in self.conf(
+ '"/php/phpinfo"', 'applications/phpinfo/working_directory'
)
- self.assertEqual(self.get()['status'], 200, 'empty rootfs')
+ assert self.get()['status'] == 200, 'empty rootfs'
- def test_php_isolation_rootfs_extensions(self):
+ def test_php_isolation_rootfs_extensions(self, is_su):
isolation_features = self.available['features']['isolation'].keys()
- if not self.is_su:
+ if not is_su:
if 'user' not in isolation_features:
- print('requires unprivileged userns or root')
- raise unittest.SkipTest()
+ pytest.skip('requires unprivileged userns or root')
if not 'unprivileged_userns_clone' in isolation_features:
- print('requires unprivileged userns or root')
- raise unittest.SkipTest()
+ pytest.skip('requires unprivileged userns or root')
if 'mnt' not in isolation_features:
- print('requires mnt ns')
- raise unittest.SkipTest()
+ pytest.skip('requires mnt ns')
isolation = {
- 'rootfs': self.current_dir,
- 'namespaces': {
- 'credential': not self.is_su,
- 'mount': not self.is_su,
- },
+ 'rootfs': option.test_dir,
+ 'namespaces': {'credential': not is_su, 'mount': not is_su},
}
self.load('list-extensions', isolation=isolation)
- self.assertIn(
- 'success',
- self.conf(
- '"/php/list-extensions"', 'applications/list-extensions/root'
- ),
+ assert 'success' in self.conf(
+ '"/php/list-extensions"', 'applications/list-extensions/root'
)
- self.assertIn(
- 'success',
- self.conf(
- {'file': '/php/list-extensions/php.ini'},
- 'applications/list-extensions/options',
- ),
+ assert 'success' in self.conf(
+ {'file': '/php/list-extensions/php.ini'},
+ 'applications/list-extensions/options',
)
- self.assertIn(
- 'success',
- self.conf(
- '"/php/list-extensions"',
- 'applications/list-extensions/working_directory',
- ),
+ assert 'success' in self.conf(
+ '"/php/list-extensions"',
+ 'applications/list-extensions/working_directory',
)
extensions = self.getjson()['body']
- self.assertIn('json', extensions, 'json in extensions list')
- self.assertIn('unit', extensions, 'unit in extensions list')
+ assert 'json' in extensions, 'json in extensions list'
+ assert 'unit' in extensions, 'unit in extensions list'
-
- def test_php_isolation_rootfs_no_language_libs(self):
+ def test_php_isolation_rootfs_no_language_libs(self, is_su):
isolation_features = self.available['features']['isolation'].keys()
- if not self.is_su:
+ if not is_su:
if 'user' not in isolation_features:
- print('requires unprivileged userns or root')
- raise unittest.SkipTest()
+ pytest.skip('requires unprivileged userns or root')
if not 'unprivileged_userns_clone' in isolation_features:
- print('requires unprivileged userns or root')
- raise unittest.SkipTest()
+ pytest.skip('requires unprivileged userns or root')
if 'mnt' not in isolation_features:
- print('requires mnt ns')
- raise unittest.SkipTest()
+ pytest.skip('requires mnt ns')
isolation = {
- 'rootfs': self.current_dir,
+ 'rootfs': option.test_dir,
'automount': {'language_deps': False},
- 'namespaces': {
- 'credential': not self.is_su,
- 'mount': not self.is_su,
- },
+ 'namespaces': {'credential': not is_su, 'mount': not is_su},
}
self.load('list-extensions', isolation=isolation)
- self.assertIn(
- 'success',
- self.conf(
- '"/php/list-extensions"', 'applications/list-extensions/root'
- ),
+ assert 'success' in self.conf(
+ '"/php/list-extensions"', 'applications/list-extensions/root'
)
- self.assertIn(
- 'success',
- self.conf(
- {'file': '/php/list-extensions/php.ini'},
- 'applications/list-extensions/options',
- ),
+ assert 'success' in self.conf(
+ {'file': '/php/list-extensions/php.ini'},
+ 'applications/list-extensions/options',
)
- self.assertIn(
- 'success',
- self.conf(
- '"/php/list-extensions"',
- 'applications/list-extensions/working_directory',
- ),
+ assert 'success' in self.conf(
+ '"/php/list-extensions"',
+ 'applications/list-extensions/working_directory',
)
extensions = self.getjson()['body']
- self.assertIn('unit', extensions, 'unit in extensions list')
- self.assertNotIn('json', extensions, 'json not in extensions list')
+ assert 'unit' in extensions, 'unit in extensions list'
+ assert 'json' not in extensions, 'json not in extensions list'
- self.assertIn(
- 'success',
- self.conf(
- {'language_deps': True},
- 'applications/list-extensions/isolation/automount',
- ),
+ assert 'success' in self.conf(
+ {'language_deps': True},
+ 'applications/list-extensions/isolation/automount',
)
extensions = self.getjson()['body']
- self.assertIn('unit', extensions, 'unit in extensions list 2')
- self.assertIn('json', extensions, 'json in extensions list 2')
-
+ assert 'unit' in extensions, 'unit in extensions list 2'
+ assert 'json' in extensions, 'json in extensions list 2'
-if __name__ == '__main__':
- TestPHPIsolation.main()