mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
b5a8b85a91
commit
e8601bf627
@ -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. """
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user