diff options
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r-- | tests/unittests/test_util.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 38ab0c96..0cb41520 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -5,8 +5,8 @@ import stat import yaml from mocker import MockerTestCase -from tests.unittests import helpers -from unittest import TestCase +from . import helpers +import unittest from cloudinit import importer from cloudinit import util @@ -31,7 +31,7 @@ class FakeSelinux(object): self.restored.append(path) -class TestGetCfgOptionListOrStr(TestCase): +class TestGetCfgOptionListOrStr(unittest.TestCase): def test_not_found_no_default(self): """None is returned if key is not found and no default given.""" config = {} @@ -124,16 +124,21 @@ class TestWriteFile(MockerTestCase): def test_restorecon_if_possible_is_called(self): """Make sure the selinux guard is called correctly.""" + my_file = os.path.join(self.tmp, "my_file") + with open(my_file, "w") as fp: + fp.write("My Content") + import_mock = self.mocker.replace(importer.import_module, passthrough=False) import_mock('selinux') - fake_se = FakeSelinux('/etc/hosts') + + fake_se = FakeSelinux(my_file) self.mocker.result(fake_se) self.mocker.replay() - with util.SeLinuxGuard("/etc/hosts") as is_on: + with util.SeLinuxGuard(my_file) as is_on: self.assertTrue(is_on) self.assertEqual(1, len(fake_se.restored)) - self.assertEqual('/etc/hosts', fake_se.restored[0]) + self.assertEqual(my_file, fake_se.restored[0]) class TestDeleteDirContents(MockerTestCase): @@ -201,20 +206,20 @@ class TestDeleteDirContents(MockerTestCase): self.assertDirEmpty(self.tmp) -class TestKeyValStrings(TestCase): +class TestKeyValStrings(unittest.TestCase): def test_keyval_str_to_dict(self): expected = {'1': 'one', '2': 'one+one', 'ro': True} cmdline = "1=one ro 2=one+one" self.assertEqual(expected, util.keyval_str_to_dict(cmdline)) -class TestGetCmdline(TestCase): +class TestGetCmdline(unittest.TestCase): def test_cmdline_reads_debug_env(self): os.environ['DEBUG_PROC_CMDLINE'] = 'abcd 123' self.assertEqual(os.environ['DEBUG_PROC_CMDLINE'], util.get_cmdline()) -class TestLoadYaml(TestCase): +class TestLoadYaml(unittest.TestCase): mydefault = "7b03a8ebace993d806255121073fed52" def test_simple(self): |