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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2017-11-03 17:34:30 +05:30 committed by James Valleroy
parent b5a8b85a91
commit e8601bf627
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -19,20 +19,14 @@
Test module for actions utilities that modify configuration. Test module for actions utilities that modify configuration.
""" """
import os
import shutil import shutil
import tempfile
import unittest import unittest
from plinth.actions import superuser_run, run from plinth.actions import superuser_run, run
from plinth import cfg 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): class TestPrivileged(unittest.TestCase):
"""Verify that privileged actions perform as expected. """Verify that privileged actions perform as expected.
@ -42,13 +36,17 @@ class TestPrivileged(unittest.TestCase):
""" """
@classmethod @classmethod
def setUpClass(cls): 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('/bin/echo', cfg.actions_dir)
shutil.copy('/usr/bin/id', cfg.actions_dir) shutil.copy('/usr/bin/id', cfg.actions_dir)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
os.remove(os.path.join(cfg.actions_dir, 'echo')) """Cleanup after all the tests are completed."""
os.remove(os.path.join(cfg.actions_dir, 'id')) cls.action_directory.cleanup()
def notest_run_as_root(self): def notest_run_as_root(self):
"""1. Privileged actions run as root. """ """1. Privileged actions run as root. """