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/common.py | 8 -------- 1 file changed, 8 deletions(-) (limited to 'testsuite/common.py') diff --git a/testsuite/common.py b/testsuite/common.py index 9db2cb94a..3c0ad82d7 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -245,14 +245,6 @@ class DBModelTestCase(Bcfg2TestCase): self.assertItemsEqual(list(model.objects.all()), []) -def syncdb(modeltest): - """ Given an instance of a :class:`DBModelTestCase` object, sync - and clean the database """ - inst = modeltest(methodName='test_syncdb') - inst.test_syncdb() - inst.test_cleandb() - - # in order for patchIf() to decorate a function in the same way as # patch(), we override the default behavior of __enter__ and __exit__ # on the _patch() object to basically be noops. -- cgit v1.2.3-1-g7c22 From 007d56a7044b273bf974357149cff616d82ac23f Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 5 Sep 2016 17:36:44 +0200 Subject: testsuite: Unlink database before syncing This prevents false test results with database files staying around in the local development directory. --- testsuite/common.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'testsuite/common.py') diff --git a/testsuite/common.py b/testsuite/common.py index 3c0ad82d7..6cb880226 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -223,18 +223,29 @@ class DBModelTestCase(Bcfg2TestCase): import django.core.management from django.core.exceptions import ImproperlyConfigured - if django.VERSION[0] == 1 and django.VERSION[1] < 7: - try: - django.core.management.call_command('syncdb', interactive=False, - verbosity=0) - except ImproperlyConfigured: - pass + dbfile = django.conf.settings.DATABASES['default']['NAME'] + # Close all connections to the old database + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + for connection in django.db.connections.all(): + connection.close() + else: + django.db.close_connection() + + # Remove old database + if os.path.exists(dbfile): + os.unlink(dbfile) + self.assertFalse(os.path.exists(dbfile)) + + # Create new + if django.VERSION[0] == 1 and django.VERSION[1] < 7: + django.core.management.call_command('syncdb', interactive=False, + verbosity=0) django.core.management.call_command('migrate', interactive=False, verbosity=0) - self.assertTrue( - os.path.exists( - django.conf.settings.DATABASES['default']['NAME'])) + + # Check if database exists now + self.assertTrue(os.path.exists(dbfile)) @skipUnless(has_django, "Django not found, skipping") def test_cleandb(self): -- cgit v1.2.3-1-g7c22 From 1b37c187acc99e8d4410926ae73d8efb94d79b98 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 5 Sep 2016 17:38:02 +0200 Subject: testsuite: Increase verbosity of management commands This helps debugging on errors. --- testsuite/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'testsuite/common.py') diff --git a/testsuite/common.py b/testsuite/common.py index 6cb880226..944471ade 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -240,9 +240,9 @@ class DBModelTestCase(Bcfg2TestCase): # Create new if django.VERSION[0] == 1 and django.VERSION[1] < 7: django.core.management.call_command('syncdb', interactive=False, - verbosity=0) + verbosity=1) django.core.management.call_command('migrate', interactive=False, - verbosity=0) + verbosity=1) # Check if database exists now self.assertTrue(os.path.exists(dbfile)) -- cgit v1.2.3-1-g7c22