summaryrefslogtreecommitdiffhomepage
path: root/test/test_java_isolation_rootfs.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_java_isolation_rootfs.py
parent77ecb6ab49257dd662aa9c461fed3dc1d74e5092 (diff)
downloadunit-d5e915934066c77a59d211efafca10c117b73d05.tar.gz
unit-d5e915934066c77a59d211efafca10c117b73d05.tar.bz2
Tests: migrated to the pytest.
Diffstat (limited to '')
-rw-r--r--test/test_java_isolation_rootfs.py61
1 files changed, 26 insertions, 35 deletions
diff --git a/test/test_java_isolation_rootfs.py b/test/test_java_isolation_rootfs.py
index 4d39bdc3..fa227469 100644
--- a/test/test_java_isolation_rootfs.py
+++ b/test/test_java_isolation_rootfs.py
@@ -1,6 +1,6 @@
import os
import subprocess
-import unittest
+import pytest
from unit.applications.lang.java import TestApplicationJava
@@ -8,15 +8,15 @@ from unit.applications.lang.java import TestApplicationJava
class TestJavaIsolationRootfs(TestApplicationJava):
prerequisites = {'modules': {'java': 'all'}}
- def setUp(self):
- if not self.is_su:
- return
+ def setup_method(self, is_su):
+ super().setup_method()
- super().setUp()
+ if not is_su:
+ return
- os.makedirs(self.testdir + '/jars')
- os.makedirs(self.testdir + '/tmp')
- os.chmod(self.testdir + '/tmp', 0o777)
+ os.makedirs(self.temp_dir + '/jars')
+ os.makedirs(self.temp_dir + '/tmp')
+ os.chmod(self.temp_dir + '/tmp', 0o777)
try:
process = subprocess.Popen(
@@ -24,7 +24,7 @@ class TestJavaIsolationRootfs(TestApplicationJava):
"mount",
"--bind",
self.pardir + "/build",
- self.testdir + "/jars",
+ self.temp_dir + "/jars",
],
stderr=subprocess.STDOUT,
)
@@ -32,54 +32,45 @@ class TestJavaIsolationRootfs(TestApplicationJava):
process.communicate()
except:
- self.fail('Cann\'t run mount process.')
+ pytest.fail('Cann\'t run mount process.')
- def tearDown(self):
- if not self.is_su:
+ def teardown_method(self, is_su):
+ if not is_su:
return
try:
process = subprocess.Popen(
- ["umount", "--lazy", self.testdir + "/jars"],
+ ["umount", "--lazy", self.temp_dir + "/jars"],
stderr=subprocess.STDOUT,
)
process.communicate()
except:
- self.fail('Cann\'t run mount process.')
+ pytest.fail('Cann\'t run mount process.')
# super teardown must happen after unmount to avoid deletion of /build
- super().tearDown()
+ super().teardown_method()
- def test_java_isolation_rootfs_chroot_war(self):
- if not self.is_su:
- print('require root')
- raise unittest.SkipTest()
+ def test_java_isolation_rootfs_chroot_war(self, is_su):
+ if not is_su:
+ pytest.skip('require root')
isolation = {
- 'rootfs': self.testdir,
+ 'rootfs': self.temp_dir,
}
self.load('empty_war', isolation=isolation)
- self.assertIn(
- 'success',
- self.conf(
- '"/"', '/config/applications/empty_war/working_directory',
- ),
+ assert 'success' in self.conf(
+ '"/"', '/config/applications/empty_war/working_directory',
)
- self.assertIn(
- 'success', self.conf('"/jars"', 'applications/empty_war/unit_jars')
+ assert 'success' in self.conf(
+ '"/jars"', 'applications/empty_war/unit_jars'
)
- self.assertIn(
- 'success',
- self.conf('"/java/empty.war"', 'applications/empty_war/webapp'),
+ assert 'success' in self.conf(
+ '"/java/empty.war"', 'applications/empty_war/webapp'
)
- self.assertEqual(self.get()['status'], 200, 'war')
-
-
-if __name__ == '__main__':
- TestJavaIsolationRootfs.main()
+ assert self.get()['status'] == 200, 'war'