summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-06-23 20:25:09 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-06-23 20:25:09 -0700
commit0fba4c0ed7fa1d71a6a9d6777cc64933f8d0005a (patch)
treecb9e9da4605d3ee206e7ba77c75197a9e5a29639
parentc33447a50c1b0a96c6e2261f7c45d2522a3fe28d (diff)
Fixed #22487: Don't flush out data from before normal TestCases
-rw-r--r--django/core/management/commands/migrate.py12
-rw-r--r--django/db/backends/creation.py9
-rw-r--r--tests/migration_test_data_persistence/tests.py15
3 files changed, 19 insertions, 17 deletions
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index 16a07bcfcd..aa0be3a7a6 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -129,6 +129,18 @@ class Command(BaseCommand):
else:
created_models = []
+ # The test runner requires us to flush after a syncdb but before migrations,
+ # so do that here.
+ if options.get("test_flush", False):
+ call_command(
+ 'flush',
+ verbosity=max(self.verbosity - 1, 0),
+ interactive=False,
+ database=db,
+ reset_sequences=False,
+ inhibit_post_migrate=True,
+ )
+
# Migrate!
if self.verbosity >= 1:
self.stdout.write(self.style.MIGRATE_HEADING("Running migrations:"))
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index 0b40244924..e8308c9a91 100644
--- a/django/db/backends/creation.py
+++ b/django/db/backends/creation.py
@@ -380,6 +380,7 @@ class BaseDatabaseCreation(object):
interactive=False,
database=self.connection.alias,
test_database=True,
+ test_flush=True,
)
# We then serialize the current state of the database into a string
@@ -389,14 +390,6 @@ class BaseDatabaseCreation(object):
if serialize:
self.connection._test_serialized_contents = self.serialize_db_to_string()
- # Finally, we flush the database to clean
- call_command(
- 'flush',
- verbosity=max(verbosity - 1, 0),
- interactive=False,
- database=self.connection.alias
- )
-
call_command('createcachetable', database=self.connection.alias)
# Ensure a connection for the side effect of initializing the test database.
diff --git a/tests/migration_test_data_persistence/tests.py b/tests/migration_test_data_persistence/tests.py
index 1b89c17b8b..0b6369db4b 100644
--- a/tests/migration_test_data_persistence/tests.py
+++ b/tests/migration_test_data_persistence/tests.py
@@ -1,11 +1,11 @@
-from django.test import TransactionTestCase
+from django.test import TransactionTestCase, TestCase
from .models import Book
class MigrationDataPersistenceTestCase(TransactionTestCase):
"""
Tests that data loaded in migrations is available if we set
- serialized_rollback = True.
+ serialized_rollback = True on TransactionTestCase
"""
available_apps = ["migration_test_data_persistence"]
@@ -18,16 +18,13 @@ class MigrationDataPersistenceTestCase(TransactionTestCase):
)
-class MigrationDataNoPersistenceTestCase(TransactionTestCase):
+class MigrationDataNormalPersistenceTestCase(TestCase):
"""
- Tests the failure case
+ Tests that data loaded in migrations is available on TestCase
"""
- available_apps = ["migration_test_data_persistence"]
- serialized_rollback = False
-
- def test_no_persistence(self):
+ def test_persistence(self):
self.assertEqual(
Book.objects.count(),
- 0,
+ 1,
)