mirror of https://github.com/django/django.git
Refs #24590 -- Ensured isolation between autodetector tests
Fixed a regression introduced in e1427cc609
when running tests in reverse order.
This commit is contained in:
parent
22a791e608
commit
8e631a3175
|
@ -226,6 +226,7 @@ class FieldDeconstructionTests(SimpleTestCase):
|
||||||
# there's no validation. We just want to check the setting stuff works.
|
# there's no validation. We just want to check the setting stuff works.
|
||||||
field = models.ForeignKey("auth.Permission", models.CASCADE)
|
field = models.ForeignKey("auth.Permission", models.CASCADE)
|
||||||
name, path, args, kwargs = field.deconstruct()
|
name, path, args, kwargs = field.deconstruct()
|
||||||
|
|
||||||
self.assertEqual(path, "django.db.models.ForeignKey")
|
self.assertEqual(path, "django.db.models.ForeignKey")
|
||||||
self.assertEqual(args, [])
|
self.assertEqual(args, [])
|
||||||
self.assertEqual(kwargs, {"to": "auth.Permission", "on_delete": models.CASCADE})
|
self.assertEqual(kwargs, {"to": "auth.Permission", "on_delete": models.CASCADE})
|
||||||
|
@ -305,6 +306,7 @@ class FieldDeconstructionTests(SimpleTestCase):
|
||||||
# there's no validation. We just want to check the setting stuff works.
|
# there's no validation. We just want to check the setting stuff works.
|
||||||
field = models.ManyToManyField("auth.Permission")
|
field = models.ManyToManyField("auth.Permission")
|
||||||
name, path, args, kwargs = field.deconstruct()
|
name, path, args, kwargs = field.deconstruct()
|
||||||
|
|
||||||
self.assertEqual(path, "django.db.models.ManyToManyField")
|
self.assertEqual(path, "django.db.models.ManyToManyField")
|
||||||
self.assertEqual(args, [])
|
self.assertEqual(args, [])
|
||||||
self.assertEqual(kwargs, {"to": "auth.Permission"})
|
self.assertEqual(kwargs, {"to": "auth.Permission"})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import AbstractBaseUser
|
from django.contrib.auth.models import AbstractBaseUser
|
||||||
from django.core.validators import RegexValidator, validate_slug
|
from django.core.validators import RegexValidator, validate_slug
|
||||||
|
@ -11,6 +12,7 @@ from django.db.migrations.loader import MigrationLoader
|
||||||
from django.db.migrations.questioner import MigrationQuestioner
|
from django.db.migrations.questioner import MigrationQuestioner
|
||||||
from django.db.migrations.state import ModelState, ProjectState
|
from django.db.migrations.state import ModelState, ProjectState
|
||||||
from django.test import TestCase, mock, override_settings
|
from django.test import TestCase, mock, override_settings
|
||||||
|
from django.test.utils import isolate_lru_cache
|
||||||
|
|
||||||
from .models import FoodManager, FoodQuerySet
|
from .models import FoodManager, FoodQuerySet
|
||||||
|
|
||||||
|
@ -1310,10 +1312,12 @@ class AutodetectorTests(TestCase):
|
||||||
|
|
||||||
@override_settings(AUTH_USER_MODEL="thirdapp.CustomUser")
|
@override_settings(AUTH_USER_MODEL="thirdapp.CustomUser")
|
||||||
def test_swappable(self):
|
def test_swappable(self):
|
||||||
|
with isolate_lru_cache(apps.get_swappable_settings_name):
|
||||||
before = self.make_project_state([self.custom_user])
|
before = self.make_project_state([self.custom_user])
|
||||||
after = self.make_project_state([self.custom_user, self.author_with_custom_user])
|
after = self.make_project_state([self.custom_user, self.author_with_custom_user])
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
|
|
||||||
# Right number/type of migrations?
|
# Right number/type of migrations?
|
||||||
self.assertNumberMigrations(changes, 'testapp', 1)
|
self.assertNumberMigrations(changes, 'testapp', 1)
|
||||||
self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"])
|
self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"])
|
||||||
|
@ -1321,11 +1325,13 @@ class AutodetectorTests(TestCase):
|
||||||
self.assertMigrationDependencies(changes, 'testapp', 0, [("__setting__", "AUTH_USER_MODEL")])
|
self.assertMigrationDependencies(changes, 'testapp', 0, [("__setting__", "AUTH_USER_MODEL")])
|
||||||
|
|
||||||
def test_swappable_changed(self):
|
def test_swappable_changed(self):
|
||||||
|
with isolate_lru_cache(apps.get_swappable_settings_name):
|
||||||
before = self.make_project_state([self.custom_user, self.author_with_user])
|
before = self.make_project_state([self.custom_user, self.author_with_user])
|
||||||
with override_settings(AUTH_USER_MODEL="thirdapp.CustomUser"):
|
with override_settings(AUTH_USER_MODEL="thirdapp.CustomUser"):
|
||||||
after = self.make_project_state([self.custom_user, self.author_with_custom_user])
|
after = self.make_project_state([self.custom_user, self.author_with_custom_user])
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
|
|
||||||
# Right number/type of migrations?
|
# Right number/type of migrations?
|
||||||
self.assertNumberMigrations(changes, 'testapp', 1)
|
self.assertNumberMigrations(changes, 'testapp', 1)
|
||||||
self.assertOperationTypes(changes, 'testapp', 0, ["AlterField"])
|
self.assertOperationTypes(changes, 'testapp', 0, ["AlterField"])
|
||||||
|
@ -1815,11 +1821,13 @@ class AutodetectorTests(TestCase):
|
||||||
@override_settings(AUTH_USER_MODEL="thirdapp.CustomUser")
|
@override_settings(AUTH_USER_MODEL="thirdapp.CustomUser")
|
||||||
def test_swappable_first_setting(self):
|
def test_swappable_first_setting(self):
|
||||||
"""Tests that swappable models get their CreateModel first."""
|
"""Tests that swappable models get their CreateModel first."""
|
||||||
|
with isolate_lru_cache(apps.get_swappable_settings_name):
|
||||||
# Make state
|
# Make state
|
||||||
before = self.make_project_state([])
|
before = self.make_project_state([])
|
||||||
after = self.make_project_state([self.custom_user_no_inherit, self.aardvark])
|
after = self.make_project_state([self.custom_user_no_inherit, self.aardvark])
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
|
|
||||||
# Right number/type of migrations?
|
# Right number/type of migrations?
|
||||||
self.assertNumberMigrations(changes, 'thirdapp', 1)
|
self.assertNumberMigrations(changes, 'thirdapp', 1)
|
||||||
self.assertOperationTypes(changes, 'thirdapp', 0, ["CreateModel", "CreateModel"])
|
self.assertOperationTypes(changes, 'thirdapp', 0, ["CreateModel", "CreateModel"])
|
||||||
|
@ -1999,6 +2007,7 @@ class AutodetectorTests(TestCase):
|
||||||
#23322 - Tests that the dependency resolver knows to explicitly resolve
|
#23322 - Tests that the dependency resolver knows to explicitly resolve
|
||||||
swappable models.
|
swappable models.
|
||||||
"""
|
"""
|
||||||
|
with isolate_lru_cache(apps.get_swappable_settings_name):
|
||||||
tenant = ModelState("a", "Tenant", [
|
tenant = ModelState("a", "Tenant", [
|
||||||
("id", models.AutoField(primary_key=True)),
|
("id", models.AutoField(primary_key=True)),
|
||||||
("primary_address", models.ForeignKey("b.Address", models.CASCADE))],
|
("primary_address", models.ForeignKey("b.Address", models.CASCADE))],
|
||||||
|
@ -2013,6 +2022,7 @@ class AutodetectorTests(TestCase):
|
||||||
after = self.make_project_state([address, tenant])
|
after = self.make_project_state([address, tenant])
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
|
|
||||||
# Right number/type of migrations?
|
# Right number/type of migrations?
|
||||||
self.assertNumberMigrations(changes, 'a', 2)
|
self.assertNumberMigrations(changes, 'a', 2)
|
||||||
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
|
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
|
||||||
|
@ -2031,6 +2041,7 @@ class AutodetectorTests(TestCase):
|
||||||
swappable models but with the swappable not being the first migrated
|
swappable models but with the swappable not being the first migrated
|
||||||
model.
|
model.
|
||||||
"""
|
"""
|
||||||
|
with isolate_lru_cache(apps.get_swappable_settings_name):
|
||||||
address = ModelState("a", "Address", [
|
address = ModelState("a", "Address", [
|
||||||
("id", models.AutoField(primary_key=True)),
|
("id", models.AutoField(primary_key=True)),
|
||||||
("tenant", models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE)),
|
("tenant", models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE)),
|
||||||
|
@ -2045,6 +2056,7 @@ class AutodetectorTests(TestCase):
|
||||||
after = self.make_project_state([address, tenant])
|
after = self.make_project_state([address, tenant])
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
|
|
||||||
# Right number/type of migrations?
|
# Right number/type of migrations?
|
||||||
self.assertNumberMigrations(changes, 'a', 2)
|
self.assertNumberMigrations(changes, 'a', 2)
|
||||||
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
|
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
|
||||||
|
@ -2062,6 +2074,7 @@ class AutodetectorTests(TestCase):
|
||||||
#23322 - Tests that the dependency resolver knows to explicitly resolve
|
#23322 - Tests that the dependency resolver knows to explicitly resolve
|
||||||
swappable models.
|
swappable models.
|
||||||
"""
|
"""
|
||||||
|
with isolate_lru_cache(apps.get_swappable_settings_name):
|
||||||
person = ModelState("a", "Person", [
|
person = ModelState("a", "Person", [
|
||||||
("id", models.AutoField(primary_key=True)),
|
("id", models.AutoField(primary_key=True)),
|
||||||
("parent1", models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, related_name='children'))
|
("parent1", models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, related_name='children'))
|
||||||
|
@ -2071,6 +2084,7 @@ class AutodetectorTests(TestCase):
|
||||||
after = self.make_project_state([person])
|
after = self.make_project_state([person])
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
|
|
||||||
# Right number/type of migrations?
|
# Right number/type of migrations?
|
||||||
self.assertNumberMigrations(changes, 'a', 1)
|
self.assertNumberMigrations(changes, 'a', 1)
|
||||||
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
|
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
|
||||||
|
|
Loading…
Reference in New Issue