summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-16 08:04:59 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-16 09:57:53 -0500
commit00627ba56075a0d0cb42356624ae6989521270bc (patch)
tree86567234d80ca6e30504a31ad4b63920a5a128dd /testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
parent12684bada59c9ddc08165dad757682514b54634c (diff)
downloadbcfg2-00627ba56075a0d0cb42356624ae6989521270bc.tar.gz
bcfg2-00627ba56075a0d0cb42356624ae6989521270bc.tar.bz2
bcfg2-00627ba56075a0d0cb42356624ae6989521270bc.zip
cleaned up Templatehelper to help avoid some event handling errors
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py')
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py55
1 files changed, 31 insertions, 24 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
index 832857601..43d594482 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
@@ -18,54 +18,59 @@ from TestPlugin import TestDirectoryBacked, TestConnector, TestPlugin, \
TestFileBacked
-class TestHelperModule(TestFileBacked):
+class TestHelperModule(Bcfg2TestCase):
test_obj = HelperModule
path = os.path.join(datastore, "test.py")
+ def get_obj(self, path=None):
+ if path is None:
+ path = self.path
+ return self.test_obj(path, fam=Mock())
+
def test__init(self):
hm = self.get_obj()
self.assertEqual(hm._module_name, "test")
self.assertEqual(hm._attrs, [])
@patch("imp.load_source")
- def test_Index(self, mock_load_source):
+ def test_HandleEvent(self, mock_load_source):
hm = self.get_obj()
mock_load_source.side_effect = ImportError
attrs = dir(hm)
- hm.Index()
+ hm.HandleEvent()
mock_load_source.assert_called_with(hm._module_name, hm.name)
self.assertEqual(attrs, dir(hm))
self.assertEqual(hm._attrs, [])
-
+
mock_load_source.reset()
mock_load_source.side_effect = None
# a regular Mock (not a MagicMock) won't automatically create
- # __export__, so this triggers a failure condition in Index
+ # __export__, so this triggers a failure condition in HandleEvent
mock_load_source.return_value = Mock()
attrs = dir(hm)
- hm.Index()
+ hm.HandleEvent()
mock_load_source.assert_called_with(hm._module_name, hm.name)
self.assertEqual(attrs, dir(hm))
self.assertEqual(hm._attrs, [])
# test reserved attributes
module = Mock()
- module.__export__ = ["_attrs", "Index", "__init__"]
+ module.__export__ = ["_attrs", "HandleEvent", "__init__"]
mock_load_source.reset()
mock_load_source.return_value = module
attrs = dir(hm)
- hm.Index()
+ hm.HandleEvent()
mock_load_source.assert_called_with(hm._module_name, hm.name)
self.assertEqual(attrs, dir(hm))
self.assertEqual(hm._attrs, [])
# test adding attributes
module = Mock()
- module.__export__ = ["foo", "bar", "baz", "Index"]
+ module.__export__ = ["foo", "bar", "baz", "HandleEvent"]
mock_load_source.reset()
mock_load_source.return_value = module
- hm.Index()
+ hm.HandleEvent()
mock_load_source.assert_called_with(hm._module_name, hm.name)
self.assertTrue(hasattr(hm, "foo"))
self.assertTrue(hasattr(hm, "bar"))
@@ -74,34 +79,36 @@ class TestHelperModule(TestFileBacked):
# test removing attributes
module = Mock()
- module.__export__ = ["foo", "bar", "quux", "Index"]
+ module.__export__ = ["foo", "bar", "quux", "HandleEvent"]
mock_load_source.reset()
mock_load_source.return_value = module
- hm.Index()
+ hm.HandleEvent()
mock_load_source.assert_called_with(hm._module_name, hm.name)
self.assertTrue(hasattr(hm, "foo"))
self.assertTrue(hasattr(hm, "bar"))
self.assertTrue(hasattr(hm, "quux"))
self.assertFalse(hasattr(hm, "baz"))
self.assertEqual(hm._attrs, ["foo", "bar", "quux"])
-
-class TestHelperSet(TestDirectoryBacked):
- test_obj = HelperSet
+class TestTemplateHelper(TestPlugin, TestConnector, TestDirectoryBacked):
+ test_obj = TemplateHelper
testfiles = ['foo.py', 'foo_bar.py', 'foo.bar.py']
ignore = ['fooo.py~', 'fooo.pyc', 'fooo.pyo']
badevents = ['foo']
+ def get_obj(self, core=None, fam=None):
+ if core is None:
+ core = Mock()
+ if fam is not None:
+ core.fam = fam
-class TestTemplateHelper(TestPlugin, TestConnector):
- test_obj = TemplateHelper
-
- def test__init(self):
- TestPlugin.test__init(self)
-
- th = self.get_obj()
- self.assertIsInstance(th.helpers, HelperSet)
+ @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()
def test_get_additional_data(self):
TestConnector.test_get_additional_data(self)
@@ -113,6 +120,6 @@ class TestTemplateHelper(TestPlugin, TestConnector):
module = Mock()
module._module_name = mname
rv[mname] = module
- th.helpers.entries['%s.py' % mname] = module
+ th.entries['%s.py' % mname] = module
actual = th.get_additional_data(Mock())
self.assertItemsEqual(actual, rv)