summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-06-08 17:12:27 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-06-08 17:13:11 -0700
commit55fa4c2d3423b051fce5663b3efc13e458fbb777 (patch)
tree9cd1c6a85959f8a1acee90f71c9ecca1aa23a729 /tests
parent25f4e71ed30befbd6af02a7d35807d0d3170e57d (diff)
[1.7.x] Fixed #22777: Add dependency on through for autodetected M2M adds
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 6d163873ad..f969ae50ac 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -77,7 +77,7 @@ class AutodetectorTests(TestCase):
def assertNumberMigrations(self, changes, app_label, number):
if len(changes.get(app_label, [])) != number:
self.fail("Incorrect number of migrations (%s) for %s (expected %s)\n%s" % (
- len(changes[app_label]),
+ len(changes.get(app_label, [])),
app_label,
number,
self.repr_changes(changes),
@@ -694,6 +694,20 @@ class AutodetectorTests(TestCase):
self.assertEqual(action.__class__.__name__, "AddField")
self.assertEqual(action.name, "publishers")
+ def test_create_with_through_model(self):
+ """
+ Adding a m2m with a through model and the models that use it should
+ be ordered correctly.
+ """
+ before = self.make_project_state([])
+ after = self.make_project_state([self.author_with_m2m_through, self.publisher, self.contract])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertNumberMigrations(changes, "testapp", 1)
+ # Right actions in right order?
+ self.assertOperationTypes(changes, "testapp", 0, ["CreateModel", "CreateModel", "CreateModel", "AddField", "AddField"])
+
def test_many_to_many_removed_before_through_model(self):
"""
Removing a ManyToManyField and the "through" model in the same change must remove