From ef87028da290f8c196075f4e8154596329d56f15 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 29 Oct 2012 09:35:39 -0400 Subject: fixed unit tests --- src/lib/Bcfg2/Server/Plugin/helpers.py | 9 ++++++--- src/lib/Bcfg2/Server/Plugins/Probes.py | 3 +++ .../Testsrc/Testlib/TestServer/TestPlugin/Testbase.py | 2 +- .../Testlib/TestServer/TestPlugins/TestMetadata.py | 17 +++++++++-------- testsuite/pylintrc.conf | 5 ++++- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py index a9e7b6067..894ed9851 100644 --- a/src/lib/Bcfg2/Server/Plugin/helpers.py +++ b/src/lib/Bcfg2/Server/Plugin/helpers.py @@ -164,18 +164,21 @@ class DatabaseBacked(Plugin): return False @staticmethod - def get_db_lock(fn): + def get_db_lock(func): """ Decorator to be used by a method of a :class:`DatabaseBacked` plugin that will update database data. """ + + @wraps(func) def _acquire_and_run(self, *args, **kwargs): + """ The decorated function """ if self._must_lock: # pylint: disable=W0212 try: self.core.db_write_lock.acquire() - rv = fn(self, *args, **kwargs) + rv = func(self, *args, **kwargs) finally: self.core.db_write_lock.release() else: - rv = fn(self, *args, **kwargs) + rv = func(self, *args, **kwargs) return rv return _acquire_and_run diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index 941bc4fd8..90dff4a66 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -186,6 +186,7 @@ class Probes(Bcfg2.Server.Plugin.Probing, self.load_data() __init__.__doc__ = Bcfg2.Server.Plugin.DatabaseBacked.__init__.__doc__ + @Bcfg2.Server.Plugin.track_statistics() def write_data(self, client): """ Write probe data out for use with bcfg2-info """ if self._use_db: @@ -288,10 +289,12 @@ class Probes(Bcfg2.Server.Plugin.Probing, self.cgroups[pgroup.hostname] = [] self.cgroups[pgroup.hostname].append(pgroup.group) + @Bcfg2.Server.Plugin.track_statistics() def GetProbes(self, meta): return self.probes.get_probe_data(meta) GetProbes.__doc__ = Bcfg2.Server.Plugin.Probing.GetProbes.__doc__ + @Bcfg2.Server.Plugin.track_statistics() def ReceiveData(self, client, datalist): if self.core.metadata_cache_mode in ['cautious', 'aggressive']: if client.hostname in self.cgroups: diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py index 7ee3697bb..f2cd39142 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py @@ -49,7 +49,7 @@ class TestDebuggable(Bcfg2TestCase): d.debug_flag = False d.debug_log("test") self.assertFalse(d.logger.error.called) - + d.logger.reset_mock() d.debug_log("test", flag=True) self.assertTrue(d.logger.error.called) diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py index 21502d1d8..b3d428642 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py @@ -102,7 +102,8 @@ class TestMetadataDB(DBModelTestCase): if HAS_DJANGO or can_skip: - class TestClientVersions(Bcfg2TestCase): + class TestClientVersions(TestDatabaseBacked): + test_obj = ClientVersions test_clients = dict(client1="1.2.0", client2="1.2.2", client3="1.3.0pre1", @@ -117,17 +118,17 @@ if HAS_DJANGO or can_skip: MetadataClientModel(hostname=client, version=version).save() def test__contains(self): - v = ClientVersions() + v = self.get_obj() self.assertIn("client1", v) self.assertIn("client5", v) self.assertNotIn("client__contains", v) def test_keys(self): - v = ClientVersions() + v = self.get_obj() self.assertItemsEqual(self.test_clients.keys(), v.keys()) def test__setitem(self): - v = ClientVersions() + v = self.get_obj() # test setting version of existing client v["client1"] = "1.2.3" @@ -153,7 +154,7 @@ if HAS_DJANGO or can_skip: self.assertEqual(client.version, None) def test__getitem(self): - v = ClientVersions() + v = self.get_obj() # test getting existing client self.assertEqual(v['client2'], "1.2.2") @@ -175,15 +176,15 @@ if HAS_DJANGO or can_skip: "%s not raised" % expected.__class__.__name__) def test__len(self): - v = ClientVersions() + v = self.get_obj() self.assertEqual(len(v), MetadataClientModel.objects.count()) def test__iter(self): - v = ClientVersions() + v = self.get_obj() self.assertItemsEqual([h for h in iter(v)], v.keys()) def test__delitem(self): - v = ClientVersions() + v = self.get_obj() # test adding new client new = "client__delitem" diff --git a/testsuite/pylintrc.conf b/testsuite/pylintrc.conf index 69b98b16e..829feaa26 100644 --- a/testsuite/pylintrc.conf +++ b/testsuite/pylintrc.conf @@ -33,7 +33,7 @@ load-plugins= # can either give multiple identifier separated by comma (,) or put this option # multiple time (only on the command line, not in the configuration file where # it should appear only once). -disable=F0401,W0142,W0511,W0603,W1201,R0201,R0801,R0901,R0902,R0903,R0904,R0921,R0922,C0302,I0011 +disable=F0401,W0142,W0511,W0603,W1201,R0201,R0801,R0901,R0902,R0903,R0904,R0921,R0922,C0302,I0011,E0100,E0101,E0102,E0106 # Some of these are disabled because they warn about things we _want_: # # * W0142: Used * or ** magic @@ -62,6 +62,9 @@ disable=F0401,W0142,W0511,W0603,W1201,R0201,R0801,R0901,R0902,R0903,R0904,R0921, # * R0801: Similar lines in files # * C0302: Too many lines in module +# Some of these are disabled because of bugs in pylint: +# * E0100,E0101,E0102,E0106: http://stackoverflow.com/questions/12514214/pylint-and-tornado-fails-on-tornado-web-authenticated + # Some of these are disabled for various other reasons: # * F0401: Unable to import a module: Bcfg2 has loads and loads of -- cgit v1.2.3-1-g7c22