diff options
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py | 28 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestOptions/TestComponents.py | 10 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestOptions/TestTypes.py | 20 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestOptions/Two.py | 3 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py | 4 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py | 9 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py | 18 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py | 26 | ||||
-rw-r--r-- | testsuite/Testsrc/Testlib/TestUtils.py | 15 | ||||
-rw-r--r-- | testsuite/Testsrc/test_code_checks.py | 1 | ||||
-rw-r--r-- | testsuite/common.py | 20 | ||||
-rw-r--r-- | testsuite/ext/ssl_protocols.py | 17 | ||||
-rw-r--r-- | testsuite/pylintrc.conf | 2 | ||||
-rw-r--r-- | testsuite/requirements.txt | 2 |
14 files changed, 118 insertions, 57 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py index 69dd562be..47d3b84ed 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py @@ -37,22 +37,6 @@ class TestPOSIXFile(TestPOSIXTool): entry.text = "text" self.assertTrue(ptool.fully_specified(entry)) - def test_is_string(self): - ptool = self.get_obj() - - for char in list(range(8)) + list(range(14, 32)): - self.assertFalse(ptool._is_string("foo" + chr(char) + "bar", - 'UTF-8')) - for char in list(range(9, 14)) + list(range(33, 128)): - self.assertTrue(ptool._is_string("foo" + chr(char) + "bar", - 'UTF-8')) - ustr = 'é' - self.assertTrue(ptool._is_string(ustr, 'UTF-8')) - if not inPy3k: - self.assertFalse(ptool._is_string("foo" + chr(128) + "bar", - 'ascii')) - self.assertFalse(ptool._is_string(ustr, 'ascii')) - def test_get_data(self): orig_entry = lxml.etree.Element("Path", name="/test", type="file") Bcfg2.Options.setup.encoding = "ascii" @@ -216,7 +200,8 @@ class TestPOSIXFile(TestPOSIXTool): mock_unlink.assert_called_with(newfile) @patch("%s.open" % builtins) - def test__get_diffs(self, mock_open): + @patch("Bcfg2.Utils") + def test__get_diffs(self, mock_utils, mock_open): orig_entry = lxml.etree.Element("Path", name="/test", type="file", mode='0644', owner='root', group='root') @@ -226,16 +211,15 @@ class TestPOSIXFile(TestPOSIXTool): ptool = self.get_obj() ptool._get_data = Mock() ptool._diff = Mock() - ptool._is_string = Mock() def reset(): - ptool._is_string.reset_mock() + mock_utils.is_string.reset_mock() ptool._get_data.reset_mock() ptool._diff.reset_mock() mock_open.reset_mock() return copy.deepcopy(orig_entry) - ptool._is_string.return_value = True + mock_utils.is_string.return_value = True ptool._get_data.return_value = (orig_entry.text, False) mock_open.return_value.read.return_value = ondisk ptool._diff.return_value = ["-test2", "+test"] @@ -250,7 +234,7 @@ class TestPOSIXFile(TestPOSIXTool): # binary data on disk entry = reset() - ptool._is_string.return_value = False + mock_utils.is_string.return_value = False ptool._get_diffs(entry, content=ondisk) self.assertFalse(mock_open.called) self.assertFalse(ptool._diff.called) @@ -258,7 +242,7 @@ class TestPOSIXFile(TestPOSIXTool): # sensitive, non-interactive -- do nothing entry = reset() - ptool._is_string.return_value = True + mock_utils.is_string.return_value = True ptool._get_diffs(entry, sensitive=True, interactive=False) self.assertFalse(mock_open.called) self.assertFalse(ptool._diff.called) 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/TestTypes.py b/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py index 404d67fdc..0b67db38a 100644 --- a/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py +++ b/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py @@ -46,21 +46,23 @@ class TestOptionTypes(Bcfg2TestCase): self.assertItemsEqual(self._test_options(["--test", "one:two three"]), ["one", "two three"]) - def test_comma_dict(self): - """parse comma-dict values.""" - self.options = [Option("--test", type=Types.comma_dict)] + def test_literal_dict(self): + """parse literal-dict values.""" + self.options = [Option("--test", type=Types.literal_dict)] expected = { "one": True, "two": 2, "three": "three", - "four": False} + "four": False, + "five": { + "a": 1, + "b": 2 + }} self.assertDictEqual( self._test_options(["--test", - "one=yes, two=2 , three=three,four=no"]), - expected) - - self.assertDictEqual( - self._test_options(["--test", "one,two=2,three=three,four=off"]), + '''{ "one": True, "two": 2, + "three": "three", "four": False, + "five": { "a": 1, "b": 2 }}''']), expected) def test_anchored_regex_list(self): 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 128d6cae5..1c2fa23a2 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) @@ -39,8 +40,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 +53,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 +66,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 +78,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 +92,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/Testlib/TestUtils.py b/testsuite/Testsrc/Testlib/TestUtils.py index 4bed67248..a37f2ecbe 100644 --- a/testsuite/Testsrc/Testlib/TestUtils.py +++ b/testsuite/Testsrc/Testlib/TestUtils.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os import sys from Bcfg2.Utils import * @@ -42,3 +43,17 @@ class TestPackedDigitRange(Bcfg2TestCase): for test in exc: self.assertNotIn(test, rng) self.assertFalse(rng.includes(test)) + + +class TestIsString(Bcfg2TestCase): + def test_is_string(self): + for char in list(range(8)) + list(range(14, 32)): + self.assertFalse(is_string("foo" + chr(char) + "bar", 'UTF-8')) + for char in list(range(9, 14)) + list(range(33, 128)): + self.assertTrue(is_string("foo" + chr(char) + "bar", 'UTF-8')) + + ustr = 'é' + self.assertTrue(is_string(ustr, 'UTF-8')) + if not inPy3k: + self.assertFalse(is_string("foo" + chr(128) + "bar", 'ascii')) + self.assertFalse(is_string(ustr, 'ascii')) 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 4c7337e0d..45cfcbf0b 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -64,6 +64,7 @@ try: set_setup_default("time_zone") set_setup_default("web_debug", False) set_setup_default("web_prefix") + set_setup_default("django_settings") import Bcfg2.DBSettings Bcfg2.DBSettings.finalize_django_config() @@ -171,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): @@ -199,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): diff --git a/testsuite/ext/ssl_protocols.py b/testsuite/ext/ssl_protocols.py new file mode 100644 index 000000000..66068d2a9 --- /dev/null +++ b/testsuite/ext/ssl_protocols.py @@ -0,0 +1,17 @@ +try: + from logilab.astng import MANAGER, scoped_nodes, node_classes + PYLINT=0 +except ImportError: + from astroid import MANAGER, scoped_nodes, node_classes + PYLINT=1 + +def ssl_transform(module): + if module.name == 'ssl': + for proto in ('SSLv23', 'TLSv1'): + module.locals['PROTOCOL_%s' % proto] = [node_classes.Const()] + +def register(linter): + if PYLINT == 0: + MANAGER.register_transformer(ssl_transform) + else: + MANAGER.register_transform(scoped_nodes.Module, ssl_transform) diff --git a/testsuite/pylintrc.conf b/testsuite/pylintrc.conf index 1d3ba8c88..50ece77db 100644 --- a/testsuite/pylintrc.conf +++ b/testsuite/pylintrc.conf @@ -19,7 +19,7 @@ persistent=no # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins=ext.exception_messages +load-plugins=ext.exception_messages,ext.ssl_protocols [MESSAGES CONTROL] diff --git a/testsuite/requirements.txt b/testsuite/requirements.txt index dce47c338..d67c64db6 100644 --- a/testsuite/requirements.txt +++ b/testsuite/requirements.txt @@ -4,6 +4,6 @@ mock sphinx pylint<0.29 pep8 -python-daemon +python-daemon<2.0.0 genshi argparse |