Fixed #33022 -- Fixed isolation of migrations.test_executor.ExecutorTests.test_custom_user().
This commit is contained in:
parent
bf4be3711a
commit
01bf679e59
|
@ -10,6 +10,7 @@ from django.db.migrations.state import ProjectState
|
||||||
from django.test import (
|
from django.test import (
|
||||||
SimpleTestCase, modify_settings, override_settings, skipUnlessDBFeature,
|
SimpleTestCase, modify_settings, override_settings, skipUnlessDBFeature,
|
||||||
)
|
)
|
||||||
|
from django.test.utils import isolate_lru_cache
|
||||||
|
|
||||||
from .test_base import MigrationTestBase
|
from .test_base import MigrationTestBase
|
||||||
|
|
||||||
|
@ -344,32 +345,39 @@ class ExecutorTests(MigrationTestBase):
|
||||||
Regression test for #22325 - references to a custom user model defined in the
|
Regression test for #22325 - references to a custom user model defined in the
|
||||||
same app are not resolved correctly.
|
same app are not resolved correctly.
|
||||||
"""
|
"""
|
||||||
executor = MigrationExecutor(connection)
|
with isolate_lru_cache(global_apps.get_swappable_settings_name):
|
||||||
self.assertTableNotExists("migrations_author")
|
executor = MigrationExecutor(connection)
|
||||||
self.assertTableNotExists("migrations_tribble")
|
self.assertTableNotExists('migrations_author')
|
||||||
# Migrate forwards
|
self.assertTableNotExists('migrations_tribble')
|
||||||
executor.migrate([("migrations", "0001_initial")])
|
# Migrate forwards
|
||||||
self.assertTableExists("migrations_author")
|
executor.migrate([('migrations', '0001_initial')])
|
||||||
self.assertTableExists("migrations_tribble")
|
self.assertTableExists('migrations_author')
|
||||||
# Make sure the soft-application detection works (#23093)
|
self.assertTableExists('migrations_tribble')
|
||||||
# Change table_names to not return auth_user during this as
|
# The soft-application detection works.
|
||||||
# it wouldn't be there in a normal run, and ensure migrations.Author
|
# Change table_names to not return auth_user during this as it
|
||||||
# exists in the global app registry temporarily.
|
# wouldn't be there in a normal run, and ensure migrations.Author
|
||||||
old_table_names = connection.introspection.table_names
|
# exists in the global app registry temporarily.
|
||||||
connection.introspection.table_names = lambda c: [x for x in old_table_names(c) if x != "auth_user"]
|
old_table_names = connection.introspection.table_names
|
||||||
migrations_apps = executor.loader.project_state(("migrations", "0001_initial")).apps
|
connection.introspection.table_names = lambda c: [
|
||||||
global_apps.get_app_config("migrations").models["author"] = migrations_apps.get_model("migrations", "author")
|
x for x in old_table_names(c) if x != 'auth_user'
|
||||||
try:
|
]
|
||||||
migration = executor.loader.get_migration("auth", "0001_initial")
|
migrations_apps = executor.loader.project_state(
|
||||||
self.assertIs(executor.detect_soft_applied(None, migration)[0], True)
|
('migrations', '0001_initial'),
|
||||||
finally:
|
).apps
|
||||||
connection.introspection.table_names = old_table_names
|
global_apps.get_app_config('migrations').models['author'] = (
|
||||||
del global_apps.get_app_config("migrations").models["author"]
|
migrations_apps.get_model('migrations', 'author')
|
||||||
# And migrate back to clean up the database
|
)
|
||||||
executor.loader.build_graph()
|
try:
|
||||||
executor.migrate([("migrations", None)])
|
migration = executor.loader.get_migration('auth', '0001_initial')
|
||||||
self.assertTableNotExists("migrations_author")
|
self.assertIs(executor.detect_soft_applied(None, migration)[0], True)
|
||||||
self.assertTableNotExists("migrations_tribble")
|
finally:
|
||||||
|
connection.introspection.table_names = old_table_names
|
||||||
|
del global_apps.get_app_config('migrations').models['author']
|
||||||
|
# Migrate back to clean up the database.
|
||||||
|
executor.loader.build_graph()
|
||||||
|
executor.migrate([('migrations', None)])
|
||||||
|
self.assertTableNotExists('migrations_author')
|
||||||
|
self.assertTableNotExists('migrations_tribble')
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIGRATION_MODULES={
|
MIGRATION_MODULES={
|
||||||
|
|
Loading…
Reference in New Issue