summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestComponents.py10
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/Two.py3
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py4
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py9
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py18
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py26
-rw-r--r--testsuite/Testsrc/test_code_checks.py1
-rw-r--r--testsuite/common.py23
8 files changed, 70 insertions, 24 deletions
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py b/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py
index 61b87de2a..b1ed4cb2b 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py
@@ -182,7 +182,8 @@ class TestImportComponentOptions(OptionTestCase):
"""test cases for component loading."""
def setUp(self):
- self.options = [Option("--cls", action=ImportComponentAction),
+ self.options = [Option("--cls", cf=("config", "cls"),
+ action=ImportComponentAction),
Option("--module", action=ImportModuleAction)]
self.result = argparse.Namespace()
@@ -227,3 +228,10 @@ class TestImportComponentOptions(OptionTestCase):
self.assertRaises(SystemExit,
self.parser.parse,
["-C", config_file, "--cls", "Bcfg2.No.Such.Thing"])
+
+ @make_config({"config": {"test": "foo", "cls": "Two"}})
+ def test_default_from_config_for_component_options(self, config_file):
+ """use default value from config file for options added by dynamic loaded component."""
+ self.parser.parse(["-C", config_file])
+ self.assertEqual(self.result.cls, Two.Two)
+ self.assertEqual(self.result.test, "foo")
diff --git a/testsuite/Testsrc/Testlib/TestOptions/Two.py b/testsuite/Testsrc/Testlib/TestOptions/Two.py
index 189e0817f..0120e8b77 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/Two.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/Two.py
@@ -1,6 +1,7 @@
"""Test module for component loading."""
+from Bcfg2.Options import Option
class Two(object):
"""Test class for component loading."""
- pass
+ options = [Option('--test', cf=("config", "test"), dest="test", default="bar")]
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/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 6f5ee18ba..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)
@@ -42,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, [])
@@ -54,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, [])
@@ -66,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, [])
@@ -77,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"))
@@ -90,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"))
diff --git a/testsuite/Testsrc/test_code_checks.py b/testsuite/Testsrc/test_code_checks.py
index ba4b19d1c..6d3c4c714 100644
--- a/testsuite/Testsrc/test_code_checks.py
+++ b/testsuite/Testsrc/test_code_checks.py
@@ -66,7 +66,6 @@ error_checks = {
"VCS.py",
"YUM24.py"],
"lib/Bcfg2/Server/Plugins": ["Deps.py",
- "Ldap.py",
"Pkgmgr.py"]
}
diff --git a/testsuite/common.py b/testsuite/common.py
index e53cfdddf..9f51cc14f 100644
--- a/testsuite/common.py
+++ b/testsuite/common.py
@@ -172,21 +172,22 @@ class Bcfg2TestCase(TestCase):
msg = "XML trees are not equal: %s"
else:
msg += ": %s"
- fullmsg = msg + "\nFirst: %s" % lxml.etree.tostring(el1) + \
+ msg += "\n%s"
+ fullmsg = "First: %s" % lxml.etree.tostring(el1) + \
"\nSecond: %s" % lxml.etree.tostring(el2)
- self.assertEqual(el1.tag, el2.tag, msg=fullmsg % "Tags differ")
+ self.assertEqual(el1.tag, el2.tag, msg=msg % ("Tags differ", fullmsg))
if el1.text is not None and el2.text is not None:
self.assertEqual(el1.text.strip(), el2.text.strip(),
- msg=fullmsg % "Text content differs")
+ msg=msg % ("Text content differs", fullmsg))
else:
self.assertEqual(el1.text, el2.text,
- msg=fullmsg % "Text content differs")
+ msg=msg % ("Text content differs", fullmsg))
self.assertItemsEqual(el1.attrib.items(), el2.attrib.items(),
- msg=fullmsg % "Attributes differ")
+ msg=msg % ("Attributes differ", fullmsg))
self.assertEqual(len(el1.getchildren()),
len(el2.getchildren()),
- msg=fullmsg % "Different numbers of children")
+ msg=msg % ("Different numbers of children", fullmsg))
matched = []
for child1 in el1.getchildren():
for child2 in el2.xpath(child1.tag):
@@ -200,10 +201,10 @@ class Bcfg2TestCase(TestCase):
continue
else:
assert False, \
- fullmsg % ("Element %s is missing from second" %
- lxml.etree.tostring(child1))
+ msg % ("Element %s is missing from second" %
+ lxml.etree.tostring(child1), fullmsg)
self.assertItemsEqual(el2.getchildren(), matched,
- msg=fullmsg % "Second has extra element(s)")
+ msg=msg % ("Second has extra element(s)", fullmsg))
class DBModelTestCase(Bcfg2TestCase):
@@ -216,6 +217,10 @@ class DBModelTestCase(Bcfg2TestCase):
""" Create the test database and sync the schema """
if self.models:
import django.core.management
+ import django
+ if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
+ django.setup()
+
django.core.management.call_command("syncdb", interactive=False,
verbosity=0)
self.assertTrue(