From 7be65237acd7fe91a6693d9c2518a8a0c849d672 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 5 Sep 2016 17:34:34 +0200 Subject: testsuite: Only sync the database once per TestCase --- testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py | 10 ++++++++++ .../Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py | 4 ++-- testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'testsuite/Testsrc') diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py index 5a82100d0..9f6a9f320 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py @@ -51,6 +51,7 @@ class TestFunctions(Bcfg2TestCase): class TestDatabaseBacked(TestPlugin): test_obj = DatabaseBacked + synced = False def setUp(self): TestPlugin.setUp(self) @@ -76,6 +77,15 @@ class TestDatabaseBacked(TestPlugin): setattr(Bcfg2.Options.setup, attr, True) self.assertRaises(PluginInitError, self.get_obj, core) + def syncdb(self, modeltest): + """ Given an instance of a :class:`DBModelTestCase` object, sync + and clean the database """ + inst = modeltest(methodName='test_syncdb') + if not self.__class__.synced: + inst.test_syncdb() + self.__class__.synced = True + inst.test_cleandb() + class TestPluginDatabaseModel(Bcfg2TestCase): """ placeholder for future tests """ diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py index f2721c9ea..5d7ed50b7 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py @@ -123,7 +123,7 @@ class TestClientVersions(TestDatabaseBacked): def setUp(self): TestDatabaseBacked.setUp(self) self.test_obj = ClientVersions - syncdb(TestMetadataDB) + self.syncdb(TestMetadataDB) for client, version in self.test_clients.items(): MetadataClientModel(hostname=client, version=version).save() @@ -1252,7 +1252,7 @@ class TestMetadataBase(TestMetadata): TestClientRunHooks.setUp(self) TestDatabaseBacked.setUp(self) Bcfg2.Options.setup.metadata_db = True - syncdb(TestMetadataDB) + self.syncdb(TestMetadataDB) def load_clients_data(self, metadata=None, xdata=None): if metadata is None: diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py index 32766b5c1..07d624b29 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py @@ -278,7 +278,7 @@ group: group:with:colons def test_probes_db(self): """ Set and retrieve probe data with database enabled """ Bcfg2.Options.setup.probes_db = True - syncdb(TestProbesDB) + self.syncdb(TestProbesDB) self._perform_tests() def test_allowed_cgroups(self): -- cgit v1.2.3-1-g7c22