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.
"""
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. """