summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-12-29 20:48:04 +0100
committerTim Graham <timograham@gmail.com>2014-12-30 10:03:41 -0500
commitd49b5851b45cee5471aef37d2b301e3084f94e08 (patch)
treeb046a41dfddfcfcd5b332ccbb538e97b5b335d5b /tests
parenta9da5dd5b6f722a230a69211ad8e00a20cafcd38 (diff)
[1.7.x] Added test for an intermediate swappable model change in migration state.
refs #22563 Backport of fca866763acb6b3414c20ca3772b94cb5d111733 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 8beda8e552..047862c390 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -89,6 +89,11 @@ class AutodetectorTests(TestCase):
("name", models.CharField(max_length=200)),
("publisher", models.ForeignKey("testapp.Publisher")),
])
+ author_with_user = ModelState("testapp", "Author", [
+ ("id", models.AutoField(primary_key=True)),
+ ("name", models.CharField(max_length=200)),
+ ("user", models.ForeignKey("auth.User")),
+ ])
author_with_custom_user = ModelState("testapp", "Author", [
("id", models.AutoField(primary_key=True)),
("name", models.CharField(max_length=200)),
@@ -1091,6 +1096,20 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="Author")
self.assertMigrationDependencies(changes, 'testapp', 0, [("__setting__", "AUTH_USER_MODEL")])
+ def test_swappable_changed(self):
+ before = self.make_project_state([self.custom_user, self.author_with_user])
+ with override_settings(AUTH_USER_MODEL="thirdapp.CustomUser"):
+ after = self.make_project_state([self.custom_user, self.author_with_custom_user])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number/type of migrations?
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, 'testapp', 0, ["AlterField"])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0, model_name="author", name='user')
+ fk_field = changes['testapp'][0].operations[0].field
+ to_model = '%s.%s' % (fk_field.rel.to._meta.app_label, fk_field.rel.to._meta.object_name)
+ self.assertEqual(to_model, 'thirdapp.CustomUser')
+
def test_add_field_with_default(self):
"""#22030 - Adding a field with a default should work."""
# Make state