From 3f16355e18cdceb37828a00a8181d9cc60815cd0 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 24 Sep 2012 14:51:36 -0400 Subject: fixed tests for pylint changes --- .../Testlib/TestServer/TestPlugin/Testhelpers.py | 6 +-- .../TestServer/TestPlugin/Testinterfaces.py | 6 +-- .../Testlib/TestServer/TestPlugins/TestMetadata.py | 5 +- .../Testlib/TestServer/TestPlugins/TestProbes.py | 57 ++++++++-------------- 4 files changed, 27 insertions(+), 47 deletions(-) (limited to 'testsuite/Testsrc/Testlib/TestServer') diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py index aea00c356..f555d15f1 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py @@ -81,7 +81,7 @@ class TestFunctions(Bcfg2TestCase): class TestDatabaseBacked(TestPlugin): test_obj = DatabaseBacked - @skipUnless(has_django, "Django not found") + @skipUnless(HAS_DJANGO, "Django not found") def test__use_db(self): core = Mock() core.setup.cfp.getboolean.return_value = True @@ -93,7 +93,7 @@ class TestDatabaseBacked(TestPlugin): db = self.get_obj(core) self.assertFalse(db._use_db) - Bcfg2.Server.Plugin.helpers.has_django = False + Bcfg2.Server.Plugin.helpers.HAS_DJANGO = False core = Mock() db = self.get_obj(core) self.assertFalse(db._use_db) @@ -102,7 +102,7 @@ class TestDatabaseBacked(TestPlugin): core.setup.cfp.getboolean.return_value = True db = self.get_obj(core) self.assertFalse(db._use_db) - Bcfg2.Server.Plugin.helpers.has_django = True + Bcfg2.Server.Plugin.helpers.HAS_DJANGO = True class TestPluginDatabaseModel(Bcfg2TestCase): diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py index 1c0af33eb..f05795b1a 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py @@ -129,7 +129,7 @@ class TestThreadedStatistics(TestStatistics): queue.empty = Mock(side_effect=Empty) ts.work_queue = queue - mock_open.side_effect = OSError + mock_open.side_effect = IOError # test that save does _not_ raise an exception even when # everything goes pear-shaped ts._save() @@ -188,7 +188,7 @@ class TestThreadedStatistics(TestStatistics): reset() mock_exists.return_value = True - mock_open.side_effect = OSError + mock_open.side_effect = IOError self.assertFalse(ts._load()) mock_exists.assert_called_with(ts.pending_file) mock_open.assert_called_with(ts.pending_file, 'r') @@ -330,7 +330,7 @@ class TestVersion(Bcfg2TestCase): test_obj = Version def get_obj(self): - return self.test_obj() + return self.test_obj(datastore) def test_get_revision(self): d = self.get_obj() diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py index 9646ee66d..2aebb0705 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py @@ -1458,14 +1458,13 @@ class TestMetadata_ClientsXML(TestMetadataBase): # decorate setUp() if can_skip or has_django: __test__ = True - + def load_clients_data(self, metadata=None, xdata=None): if metadata is None: metadata = self.get_obj() metadata.core.fam = Mock() - metadata._handle_file("clients.xml") + metadata.clients_xml = metadata._handle_file("clients.xml") metadata = TestMetadata.load_clients_data(self, metadata=metadata, xdata=xdata) return TestMetadataBase.load_clients_data(self, metadata=metadata, xdata=xdata) - diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py index 4b020dcff..34b2a0f0e 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py @@ -30,7 +30,7 @@ class FakeList(list): class TestProbesDB(DBModelTestCase): - if has_django: + if HAS_DJANGO: models = [ProbesGroupsModel, ProbesDataModel] @@ -69,13 +69,14 @@ class TestProbeData(Bcfg2TestCase): self.assertIsNotNone(data.xdata) self.assertIsNotNone(data.xdata.find("test2")) + @skipUnless(HAS_JSON, "JSON libraries not found, skipping JSON tests") def test_json(self): jdata = json.dumps(test_data) data = ProbeData(jdata) self.assertIsNotNone(data.json) self.assertItemsEqual(test_data, data.json) - @skipUnless(has_yaml, "YAML libraries not found, skipping YAML tests") + @skipUnless(HAS_YAML, "YAML libraries not found, skipping YAML tests") def test_yaml(self): jdata = yaml.dump(test_data) data = ProbeData(jdata) @@ -107,32 +108,10 @@ class TestProbeSet(TestEntrySet): fam.AddMonitor.assert_called_with(datastore, ps) TestEntrySet.test__init(self) - def test_HandleEvent(self): - ps = self.get_obj() - ps.handle_event = Mock() - - # test that events on the data store itself are skipped - evt = Mock() - evt.filename = datastore - ps.HandleEvent(evt) - self.assertFalse(ps.handle_event.called) - - # test that events on probed.xml are skipped - evt.reset_mock() - evt.filename = "probed.xml" - ps.HandleEvent(evt) - self.assertFalse(ps.handle_event.called) - - # test that other events are processed appropriately - evt.reset_mock() - evt.filename = "fooprobe" - ps.HandleEvent(evt) - ps.handle_event.assert_called_with(evt) - @patch("%s.list" % builtins, FakeList) def test_get_probe_data(self): ps = self.get_obj() - + # build some fairly complex test data for this. in the end, # we want the probe data to include only the most specific # version of a given probe, and by basename only, not full @@ -220,8 +199,9 @@ text """) rv["bar.example.com"] = ClientProbeDataSet(timestamp=time.time()) rv["bar.example.com"]["empty"] = ProbeData("") - rv["bar.example.com"]["json"] = ProbeData(json.dumps(test_data)) - if has_yaml: + if HAS_JSON: + rv["bar.example.com"]["json"] = ProbeData(json.dumps(test_data)) + if HAS_YAML: rv["bar.example.com"]["yaml"] = ProbeData(yaml.dump(test_data)) return rv @@ -268,7 +248,7 @@ text "use_database", default=False) - @skipUnless(has_django, "Django not found, skipping") + @skipUnless(HAS_DJANGO, "Django not found, skipping") @patch("Bcfg2.Server.Plugins.Probes.Probes._write_data_db", Mock()) @patch("Bcfg2.Server.Plugins.Probes.Probes._write_data_xml", Mock()) def test_write_data_xml(self): @@ -277,7 +257,7 @@ text probes._write_data_xml.assert_called_with("test") self.assertFalse(probes._write_data_db.called) - @skipUnless(has_django, "Django not found, skipping") + @skipUnless(HAS_DJANGO, "Django not found, skipping") @patch("Bcfg2.Server.Plugins.Probes.Probes._write_data_db", Mock()) @patch("Bcfg2.Server.Plugins.Probes.Probes._write_data_xml", Mock()) def test_write_data_db(self): @@ -331,17 +311,18 @@ text self.assertIsNotNone(empty) self.assertIsNotNone(empty.get("value")) self.assertEqual(empty.get("value"), "") - jdata = bardata.find("Probe[@name='json']") - self.assertIsNotNone(jdata) - self.assertIsNotNone(jdata.get("value")) - self.assertItemsEqual(test_data, json.loads(jdata.get("value"))) - if has_yaml: + if HAS_JSON: + jdata = bardata.find("Probe[@name='json']") + self.assertIsNotNone(jdata) + self.assertIsNotNone(jdata.get("value")) + self.assertItemsEqual(test_data, json.loads(jdata.get("value"))) + if HAS_YAML: ydata = bardata.find("Probe[@name='yaml']") self.assertIsNotNone(ydata) self.assertIsNotNone(ydata.get("value")) self.assertItemsEqual(test_data, yaml.load(ydata.get("value"))) - @skipUnless(has_django, "Django not found, skipping") + @skipUnless(HAS_DJANGO, "Django not found, skipping") def test__write_data_db(self): syncdb(TestProbesDB) probes = self.get_probes_object(use_db=True) @@ -393,7 +374,7 @@ text pgroups = ProbesGroupsModel.objects.filter(hostname=cname).all() self.assertEqual(len(pgroups), len(probes.cgroups[cname])) - @skipUnless(has_django, "Django not found, skipping") + @skipUnless(HAS_DJANGO, "Django not found, skipping") @patch("Bcfg2.Server.Plugins.Probes.Probes._load_data_db", Mock()) @patch("Bcfg2.Server.Plugins.Probes.Probes._load_data_xml", Mock()) def test_load_data_xml(self): @@ -402,7 +383,7 @@ text probes._load_data_xml.assert_any_call() self.assertFalse(probes._load_data_db.called) - @skipUnless(has_django, "Django not found, skipping") + @skipUnless(HAS_DJANGO, "Django not found, skipping") @patch("Bcfg2.Server.Plugins.Probes.Probes._load_data_db", Mock()) @patch("Bcfg2.Server.Plugins.Probes.Probes._load_data_xml", Mock()) def test_load_data_db(self): @@ -434,7 +415,7 @@ text self.assertItemsEqual(probes.probedata, self.get_test_probedata()) self.assertItemsEqual(probes.cgroups, self.get_test_cgroups()) - @skipUnless(has_django, "Django not found, skipping") + @skipUnless(HAS_DJANGO, "Django not found, skipping") def test__load_data_db(self): syncdb(TestProbesDB) probes = self.get_probes_object(use_db=True) -- cgit v1.2.3-1-g7c22