summaryrefslogtreecommitdiff
path: root/tests/migrations/test_executor.py
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-07-25 09:35:25 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-07-25 09:35:38 -0700
commita64bc3df77e074ddb7aa5c42eb2a84c26917a3b7 (patch)
tree30e9b5a37e18efa8b23829344e10721c56fcc38b /tests/migrations/test_executor.py
parentf44dbf74a4abf9c45d49568c7ca46363ff6e5112 (diff)
Fixed #23093: soft application detection for swapped models
Diffstat (limited to 'tests/migrations/test_executor.py')
-rw-r--r--tests/migrations/test_executor.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
index e933f9d8bd..d07eecfcef 100644
--- a/tests/migrations/test_executor.py
+++ b/tests/migrations/test_executor.py
@@ -1,6 +1,7 @@
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
from django.test import modify_settings, override_settings
+from django.apps.registry import apps as global_apps
from .test_base import MigrationTestBase
@@ -14,7 +15,7 @@ class ExecutorTests(MigrationTestBase):
test failures first, as they may be propagating into here.
"""
- available_apps = ["migrations", "migrations2"]
+ available_apps = ["migrations", "migrations2", "django.contrib.auth", "django.contrib.contenttypes"]
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_run(self):
@@ -193,7 +194,10 @@ class ExecutorTests(MigrationTestBase):
self.assertTableNotExists("migrations_tribble")
@override_settings(
- MIGRATION_MODULES={"migrations": "migrations.test_migrations_custom_user"},
+ MIGRATION_MODULES={
+ "migrations": "migrations.test_migrations_custom_user",
+ "django.contrib.auth": "django.contrib.auth.migrations",
+ },
AUTH_USER_MODEL="migrations.Author",
)
def test_custom_user(self):
@@ -208,6 +212,20 @@ class ExecutorTests(MigrationTestBase):
executor.migrate([("migrations", "0001_initial")])
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_tribble")
+ # Make sure the soft-application detection works (#23093)
+ # Change get_table_list to not return auth_user during this as
+ # it wouldn't be there in a normal run, and ensure migrations.Author
+ # exists in the global app registry temporarily.
+ old_get_table_list = connection.introspection.get_table_list
+ connection.introspection.get_table_list = lambda c: [x for x in old_get_table_list(c) if x != "auth_user"]
+ migrations_apps = executor.loader.project_state(("migrations", "0001_initial")).render()
+ global_apps.get_app_config("migrations").models["author"] = migrations_apps.get_model("migrations", "author")
+ try:
+ migration = executor.loader.get_migration("auth", "0001_initial")
+ self.assertEqual(executor.detect_soft_applied(migration), True)
+ finally:
+ connection.introspection.get_table_list = old_get_table_list
+ del global_apps.get_app_config("migrations").models["author"]
# And migrate back to clean up the database
executor.loader.build_graph()
executor.migrate([("migrations", None)])