Prevented TestNoInitialDataLoading to pollute other tests (Refs #15926)

Tests were still failing with MySQL. It seems a rollback is solving
the issue.
This commit is contained in:
Claude Paroz 2012-06-06 15:45:28 +02:00
parent f5ce1793a8
commit 2c57809a56
1 changed files with 22 additions and 16 deletions

View File

@ -1,5 +1,6 @@
from django.core import management
from django.test import TestCase
from django.db import transaction
from django.test import TestCase, TransactionTestCase
from .models import Article, Book
@ -20,16 +21,18 @@ class SampleTestCase(TestCase):
)
class TestNoInitialDataLoading(TestCase):
class TestNoInitialDataLoading(TransactionTestCase):
def test_syncdb(self):
Book.objects.all().delete()
with transaction.commit_manually():
Book.objects.all().delete()
management.call_command(
'syncdb',
verbosity=0,
load_initial_data=False
)
self.assertQuerysetEqual(Book.objects.all(), [])
management.call_command(
'syncdb',
verbosity=0,
load_initial_data=False
)
self.assertQuerysetEqual(Book.objects.all(), [])
transaction.rollback()
def test_flush(self):
# Test presence of fixture (flush called by TransactionTestCase)
@ -40,13 +43,16 @@ class TestNoInitialDataLoading(TestCase):
lambda a: a.name
)
management.call_command(
'flush',
verbosity=0,
interactive=False,
load_initial_data=False
)
self.assertQuerysetEqual(Book.objects.all(), [])
with transaction.commit_manually():
management.call_command(
'flush',
verbosity=0,
interactive=False,
commit=False,
load_initial_data=False
)
self.assertQuerysetEqual(Book.objects.all(), [])
transaction.rollback()
class FixtureTestCase(TestCase):