From e8601bf62772a8dcabeeeb0beeeec884447b0109 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 3 Nov 2017 17:34:30 +0530 Subject: [PATCH] tests: Use a temporary directory for testing actions This eliminates the case where the test module was getting installed in a different location compared to other modules. Also eliminates the need to run this test as root. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/tests/test_actions.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/plinth/tests/test_actions.py b/plinth/tests/test_actions.py index 8cc46ff46..5f7e28d21 100644 --- a/plinth/tests/test_actions.py +++ b/plinth/tests/test_actions.py @@ -19,20 +19,14 @@ Test module for actions utilities that modify configuration. """ -import os import shutil +import tempfile import unittest from plinth.actions import superuser_run, run from plinth import cfg -test_dir = os.path.split(__file__)[0] -root_dir = os.path.abspath(os.path.join(test_dir, os.path.pardir + - os.path.sep + os.path.pardir)) -cfg.actions_dir = os.path.join(root_dir, 'actions') - - class TestPrivileged(unittest.TestCase): """Verify that privileged actions perform as expected. @@ -42,13 +36,17 @@ class TestPrivileged(unittest.TestCase): """ @classmethod def setUpClass(cls): + """Initial setup for all the classes.""" + cls.action_directory = tempfile.TemporaryDirectory() + cfg.actions_dir = cls.action_directory.name + shutil.copy('/bin/echo', cfg.actions_dir) shutil.copy('/usr/bin/id', cfg.actions_dir) @classmethod def tearDownClass(cls): - os.remove(os.path.join(cfg.actions_dir, 'echo')) - os.remove(os.path.join(cfg.actions_dir, 'id')) + """Cleanup after all the tests are completed.""" + cls.action_directory.cleanup() def notest_run_as_root(self): """1. Privileged actions run as root. """