diff options
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestServer/TestPlugins')
5 files changed, 62 insertions, 17 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py index 1bf208c3e..5a8c44cd5 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py @@ -98,7 +98,7 @@ class TestBundler(TestPlugin, TestStructure, TestXMLDirectoryBacked): lxml.etree.SubElement(expected['indep'], "Service", name="baz") metadata = Mock() - metadata.bundles = ["error", "xinclude", "has_dep", "indep"] + metadata.bundles = set(["error", "xinclude", "has_dep", "indep"]) metadata.version_info = Bcfg2VersionInfo('1.4.0') rv = b.BuildStructures(metadata) @@ -131,7 +131,7 @@ class TestBundler(TestPlugin, TestStructure, TestXMLDirectoryBacked): lxml.etree.SubElement(expected['has_dep'], "Package", name="foo") metadata = Mock() - metadata.bundles = ["has_dep"] + metadata.bundles = set(["has_dep"]) metadata.version_info = Bcfg2VersionInfo('1.3.0') rv = b.BuildStructures(metadata) diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py index 9b4a6af88..3c660099e 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py @@ -22,6 +22,10 @@ from Testinterfaces import TestGoalValidator class TestDefaults(TestRules, TestGoalValidator): test_obj = Defaults + def setUp(self): + TestRules.setUp(self) + set_setup_default("defaults_replace_name", True) + def get_obj(self, *args, **kwargs): return TestRules.get_obj(self, *args, **kwargs) @@ -91,3 +95,8 @@ class TestDefaults(TestRules, TestGoalValidator): def test_regex(self): self._do_test('regex') + + def test_replace_name(self): + Bcfg2.Options.setup.defaults_replace_name = True + self._do_test('replace_name') + Bcfg2.Options.setup.defaults_replace_name = False diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py index 36baee899..8c7f3c5d7 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py @@ -29,11 +29,14 @@ class TestPropertyFile(Bcfg2TestCase): test_obj = PropertyFile path = os.path.join(datastore, "test") - def get_obj(self, path=None): + def get_obj(self, path=None, core=None, *args, **kwargs): set_setup_default("writes_enabled", False) if path is None: path = self.path - return self.test_obj(path) + if core is None: + core = Mock() + core.metadata_cache_mode = 'none' + return self.test_obj(path, core, *args, **kwargs) def test_write(self): pf = self.get_obj() @@ -97,6 +100,9 @@ class TestJSONPropertyFile(TestFileBacked, TestPropertyFile): TestFileBacked.setUp(self) TestPropertyFile.setUp(self) + def get_obj(self, *args, **kwargs): + return TestPropertyFile.get_obj(self, *args, **kwargs) + @patch("%s.loads" % JSON) def test_Index(self, mock_loads): pf = self.get_obj() @@ -137,6 +143,9 @@ class TestYAMLPropertyFile(TestFileBacked, TestPropertyFile): TestFileBacked.setUp(self) TestPropertyFile.setUp(self) + def get_obj(self, *args, **kwargs): + return TestPropertyFile.get_obj(self, *args, **kwargs) + @patch("yaml.load") def test_Index(self, mock_load): pf = self.get_obj() @@ -179,7 +188,7 @@ class TestXMLPropertyFile(TestPropertyFile, TestStructFile): set_setup_default("automatch", False) def get_obj(self, *args, **kwargs): - return TestStructFile.get_obj(self, *args, **kwargs) + return TestPropertyFile.get_obj(self, *args, **kwargs) @patch("%s.open" % builtins) def test__write(self, mock_open): diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py index 45f3671e8..88b334edf 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py @@ -32,6 +32,7 @@ class TestRules(TestPrioDir): group=lxml.etree.Element("SEPort", name="6789/tcp"), children=lxml.etree.Element("Path", name="/etc/child-entries"), regex=lxml.etree.Element("Package", name="regex"), + replace_name=lxml.etree.Element("POSIXUser", name="regex"), slash=lxml.etree.Element("Path", name="/etc/trailing/slash"), no_slash=lxml.etree.Element("Path", name="/etc/no/trailing/slash/")) @@ -53,6 +54,8 @@ class TestRules(TestPrioDir): group="root", mode="0775"), regex=lxml.etree.Element("Package", name="regex", type="yum", version="any"), + replace_name=lxml.etree.Element("POSIXUser", name="regex", + home="/foobar%{bar}/regex"), slash=lxml.etree.Element("Path", name="/etc/trailing/slash", type="directory", owner="root", group="root", mode="0600"), @@ -70,6 +73,8 @@ class TestRules(TestPrioDir): in_file = copy.deepcopy(concrete) in_file['regex'].set("name", ".*") + in_file['replace_name'].set("home", "/foobar%{bar}/%{name}") + in_file['replace_name'].set("name", ".*") in_file['slash'].set("name", "/etc/trailing/slash/") in_file['no_slash'].set("name", "/etc/no/trailing/slash") @@ -91,6 +96,7 @@ class TestRules(TestPrioDir): rules3 = lxml.etree.Element("Rules", priority="10") rules3.append(in_file['duplicate']) rules3.append(in_file['regex']) + rules3.append(in_file['replace_name']) rules3.append(in_file['slash']) rules = {"rules1.xml": rules1, "rules2.xml": rules2, "rules3.xml": rules3} @@ -99,6 +105,7 @@ class TestRules(TestPrioDir): TestPrioDir.setUp(self) set_setup_default("lax_decryption", True) set_setup_default("rules_regex", False) + set_setup_default("rules_replace_name", False) def get_child(self, name): """ Turn one of the XML documents in `rules` into a child @@ -169,6 +176,17 @@ class TestRules(TestPrioDir): self._do_test('regex') Bcfg2.Options.setup.rules_regex = False + def test_replace_name(self): + """ Test that Rules handles replaces name in attribues with regular expressions """ + Bcfg2.Options.setup.rules_regex = False + Bcfg2.Options.setup.rules_replace_name = False + self._do_test_failure('replace_name', handles=False) + Bcfg2.Options.setup.rules_regex = True + Bcfg2.Options.setup.rules_replace_name = True + self._do_test('replace_name') + Bcfg2.Options.setup.rules_regex = False + Bcfg2.Options.setup.rules_replace_name = False + def test_slash(self): """ Test that Rules handles trailing slashes on Path entries """ self._do_test('slash') diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py index 128d6cae5..a470dca67 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py @@ -2,6 +2,7 @@ import os import sys import Bcfg2.Server.Plugin from mock import Mock, MagicMock, patch +from Bcfg2.Utils import safe_module_name from Bcfg2.Server.Plugins.TemplateHelper import * # add all parent testsuite directories to sys.path to allow (most) @@ -22,10 +23,13 @@ class TestHelperModule(Bcfg2TestCase): test_obj = HelperModule path = os.path.join(datastore, "test.py") - def get_obj(self, path=None): + def get_obj(self, path=None, core=None): if path is None: path = self.path - return self.test_obj(path) + if core is None: + core = Mock() + core.metadata_cache_mode = 'none' + return self.test_obj(path, core) def test__init(self): hm = self.get_obj() @@ -39,8 +43,9 @@ class TestHelperModule(Bcfg2TestCase): mock_load_source.side_effect = ImportError attrs = dir(hm) hm.HandleEvent() - mock_load_source.assert_called_with(safe_module_name(hm._module_name), - hm.name) + mock_load_source.assert_called_with( + safe_module_name('TemplateHelper', hm._module_name), + hm.name) self.assertEqual(attrs, dir(hm)) self.assertEqual(hm._attrs, []) @@ -51,8 +56,9 @@ class TestHelperModule(Bcfg2TestCase): mock_load_source.return_value = Mock() attrs = dir(hm) hm.HandleEvent() - mock_load_source.assert_called_with(safe_module_name(hm._module_name), - hm.name) + mock_load_source.assert_called_with( + safe_module_name('TemplateHelper', hm._module_name), + hm.name) self.assertEqual(attrs, dir(hm)) self.assertEqual(hm._attrs, []) @@ -63,8 +69,9 @@ class TestHelperModule(Bcfg2TestCase): mock_load_source.return_value = module attrs = dir(hm) hm.HandleEvent() - mock_load_source.assert_called_with(safe_module_name(hm._module_name), - hm.name) + mock_load_source.assert_called_with( + safe_module_name('TemplateHelper', hm._module_name), + hm.name) self.assertEqual(attrs, dir(hm)) self.assertEqual(hm._attrs, []) @@ -74,8 +81,9 @@ class TestHelperModule(Bcfg2TestCase): mock_load_source.reset() mock_load_source.return_value = module hm.HandleEvent() - mock_load_source.assert_called_with(safe_module_name(hm._module_name), - hm.name) + mock_load_source.assert_called_with( + safe_module_name('TemplateHelper', hm._module_name), + hm.name) self.assertTrue(hasattr(hm, "foo")) self.assertTrue(hasattr(hm, "bar")) self.assertTrue(hasattr(hm, "baz")) @@ -87,8 +95,9 @@ class TestHelperModule(Bcfg2TestCase): mock_load_source.reset() mock_load_source.return_value = module hm.HandleEvent() - mock_load_source.assert_called_with(safe_module_name(hm._module_name), - hm.name) + mock_load_source.assert_called_with( + safe_module_name('TemplateHelper', hm._module_name), + hm.name) self.assertTrue(hasattr(hm, "foo")) self.assertTrue(hasattr(hm, "bar")) self.assertTrue(hasattr(hm, "quux")) |