From b034bf67034c4f0e966ebd207ba2f407f6f15fa8 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 25 May 2023 16:56:14 +0100 Subject: Tests: assertion related fixes. --- test/test_python_isolation_chroot.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'test/test_python_isolation_chroot.py') diff --git a/test/test_python_isolation_chroot.py b/test/test_python_isolation_chroot.py index 349ec869..dd0dede0 100644 --- a/test/test_python_isolation_chroot.py +++ b/test/test_python_isolation_chroot.py @@ -15,24 +15,22 @@ class TestPythonIsolation(TestApplicationPython): self.load('ns_inspect', isolation=isolation) - assert ( + assert not ( self.getjson(url=f'/?path={temp_dir}')['body']['FileExists'] - == False ), 'temp_dir does not exists in rootfs' - assert ( - self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True - ), 'no /proc/self' + assert self.getjson(url='/?path=/proc/self')['body'][ + 'FileExists' + ], 'no /proc/self' - assert ( - self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False + assert not ( + self.getjson(url='/?path=/dev/pts')['body']['FileExists'] ), 'no /dev/pts' - assert ( + assert not ( self.getjson(url='/?path=/sys/kernel')['body']['FileExists'] - == False ), 'no /sys/kernel' ret = self.getjson(url='/?path=/app/python/ns_inspect') - assert ret['body']['FileExists'] == True, 'application exists in rootfs' + assert ret['body']['FileExists'], 'application exists in rootfs' -- cgit From ce2405ec3dd97e8bdf8f63312e3c6ce59ef562d4 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 12 Jun 2023 14:16:59 +0100 Subject: Tests: prerequisites checking reworked. Prerequisites check moved to the module level to simplify class structure. Discovery and prerequisites checks functions moved to the separate files. Introduced "require" fixture to provide per-test requirements check. --- test/test_python_isolation_chroot.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'test/test_python_isolation_chroot.py') diff --git a/test/test_python_isolation_chroot.py b/test/test_python_isolation_chroot.py index dd0dede0..fd16c1fb 100644 --- a/test/test_python_isolation_chroot.py +++ b/test/test_python_isolation_chroot.py @@ -1,17 +1,11 @@ -import pytest from unit.applications.lang.python import TestApplicationPython +prerequisites = {'modules': {'python': 'any'}, 'privileged_user': True} -class TestPythonIsolation(TestApplicationPython): - prerequisites = {'modules': {'python': 'any'}} - - def test_python_isolation_chroot(self, is_su, temp_dir): - if not is_su: - pytest.skip('requires root') - isolation = { - 'rootfs': temp_dir, - } +class TestPythonIsolation(TestApplicationPython): + def test_python_isolation_chroot(self, temp_dir): + isolation = {'rootfs': temp_dir} self.load('ns_inspect', isolation=isolation) -- cgit From c183bd8749a19477390f8cb77efe5f6d223f0905 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 14 Jun 2023 18:20:09 +0100 Subject: 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. --- test/test_python_isolation_chroot.py | 37 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'test/test_python_isolation_chroot.py') diff --git a/test/test_python_isolation_chroot.py b/test/test_python_isolation_chroot.py index fd16c1fb..60fac5ef 100644 --- a/test/test_python_isolation_chroot.py +++ b/test/test_python_isolation_chroot.py @@ -1,30 +1,29 @@ -from unit.applications.lang.python import TestApplicationPython +from unit.applications.lang.python import ApplicationPython prerequisites = {'modules': {'python': 'any'}, 'privileged_user': True} +client = ApplicationPython() -class TestPythonIsolation(TestApplicationPython): - def test_python_isolation_chroot(self, temp_dir): - isolation = {'rootfs': temp_dir} - self.load('ns_inspect', isolation=isolation) +def test_python_isolation_chroot(temp_dir): + client.load('ns_inspect', isolation={'rootfs': temp_dir}) - assert not ( - self.getjson(url=f'/?path={temp_dir}')['body']['FileExists'] - ), 'temp_dir does not exists in rootfs' + assert not ( + client.getjson(url=f'/?path={temp_dir}')['body']['FileExists'] + ), 'temp_dir does not exists in rootfs' - assert self.getjson(url='/?path=/proc/self')['body'][ - 'FileExists' - ], 'no /proc/self' + assert client.getjson(url='/?path=/proc/self')['body'][ + 'FileExists' + ], 'no /proc/self' - assert not ( - self.getjson(url='/?path=/dev/pts')['body']['FileExists'] - ), 'no /dev/pts' + assert not ( + client.getjson(url='/?path=/dev/pts')['body']['FileExists'] + ), 'no /dev/pts' - assert not ( - self.getjson(url='/?path=/sys/kernel')['body']['FileExists'] - ), 'no /sys/kernel' + assert not ( + client.getjson(url='/?path=/sys/kernel')['body']['FileExists'] + ), 'no /sys/kernel' - ret = self.getjson(url='/?path=/app/python/ns_inspect') + ret = client.getjson(url='/?path=/app/python/ns_inspect') - assert ret['body']['FileExists'], 'application exists in rootfs' + assert ret['body']['FileExists'], 'application exists in rootfs' -- cgit