summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py28
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestComponents.py10
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestTypes.py20
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/Two.py3
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py26
-rw-r--r--testsuite/Testsrc/Testlib/TestUtils.py15
-rw-r--r--testsuite/Testsrc/test_code_checks.py1
-rw-r--r--testsuite/common.py1
8 files changed, 60 insertions, 44 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/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 bdf0c01cb..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()