summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-04 16:21:03 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-04 16:21:03 -0500
commitc3c449f509e5f849212e853b410b7b74341d3e1e (patch)
tree068f91aa28adf40b77c29cbe4d2a8c6f5c9411e7 /testsuite
parent1f6cb52d0c43f842766f3ecd6c8286f0f4eed5c2 (diff)
downloadbcfg2-c3c449f509e5f849212e853b410b7b74341d3e1e.tar.gz
bcfg2-c3c449f509e5f849212e853b410b7b74341d3e1e.tar.bz2
bcfg2-c3c449f509e5f849212e853b410b7b74341d3e1e.zip
testsuite: added unit tests for Bundler
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py
new file mode 100644
index 000000000..bc6a21b84
--- /dev/null
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py
@@ -0,0 +1,72 @@
+import os
+import sys
+import lxml.etree
+from mock import Mock, MagicMock, patch
+from Bcfg2.Server.Plugins.Bundler import *
+from Bcfg2.Server.Plugin import PluginExecutionError
+
+# add all parent testsuite directories to sys.path to allow (most)
+# relative imports in python 2.4
+path = os.path.dirname(__file__)
+while path != "/":
+ if os.path.basename(path).lower().startswith("test"):
+ sys.path.append(path)
+ if os.path.basename(path) == "testsuite":
+ break
+ path = os.path.dirname(path)
+from common import *
+from TestPlugin import TestStructFile, TestPlugin, TestStructure, \
+ TestXMLDirectoryBacked
+
+
+class TestBundleFile(TestStructFile):
+ test_obj = BundleFile
+ path = os.path.join(datastore, "test", "test1.xml")
+
+ def test_bundle_name(self):
+ cases = [("foo.xml", "foo"),
+ ("foo.bar.xml", "foo.bar"),
+ ("foo-bar-baz.xml", "foo-bar-baz"),
+ ("foo....xml", "foo..."),
+ ("foo.genshi", "foo")]
+ bf = self.get_obj()
+ for fname, bname in cases:
+ bf.name = fname
+ self.assertEqual(bf.bundle_name, bname)
+
+
+class TestBundler(TestPlugin, TestStructure, TestXMLDirectoryBacked):
+ test_obj = Bundler
+
+ def get_obj(self, core=None):
+ @patch("%s.%s.add_directory_monitor" % (self.test_obj.__module__,
+ self.test_obj.__name__),
+ Mock())
+ def inner():
+ return TestPlugin.get_obj(self, core=core)
+ return inner()
+
+ @patch("Bcfg2.Server.Plugin.XMLDirectoryBacked.HandleEvent")
+ def test_HandleEvent(self, mock_HandleEvent):
+ b = self.get_obj()
+ b.bundles = dict(foo=Mock(), bar=Mock())
+ b.entries = {"foo.xml": BundleFile("foo.xml"),
+ "baz.xml": BundleFile("baz.xml")}
+ event = Mock()
+ b.HandleEvent(event)
+ mock_HandleEvent.assert_called_with(b, event)
+ self.assertItemsEqual(b.bundles,
+ dict(foo=b.entries['foo.xml'],
+ baz=b.entries['baz.xml']))
+
+ def test_BuildStructures(self):
+ b = self.get_obj()
+ b.bundles = dict(foo=Mock(), bar=Mock(), baz=Mock())
+ metadata = Mock()
+ metadata.bundles = ["foo", "baz"]
+
+ self.assertItemsEqual(b.BuildStructures(metadata),
+ [b.bundles[n].XMLMatch.return_value
+ for n in metadata.bundles])
+ for bname in metadata.bundles:
+ b.bundles[bname].XMLMatch.assert_called_with(metadata)