diff options
| author | Tim Graham <timograham@gmail.com> | 2014-06-25 08:53:09 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-06-25 10:02:12 -0400 |
| commit | e0cd07ec2f394e6db3d17de19809a8f377cd1578 (patch) | |
| tree | e378c6bed42379a8712c6dcb64bcd157a0484b61 /tests | |
| parent | e769846eec14d3b522c132104e2ecba9cf96d3b0 (diff) | |
Fixed #22903 -- Fixed migration generation if index_together or unique_together is removed from a model.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 33083c38b5..cedfa755b4 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -567,6 +567,44 @@ class AutodetectorTests(TestCase): self.assertEqual(action2.__class__.__name__, "AlterUniqueTogether") self.assertEqual(action2.unique_together, set([("title", "newfield")])) + def test_remove_index_together(self): + author_index_together = ModelState("testapp", "Author", [ + ("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)) + ], {"index_together": [("id", "name")]}) + + before = self.make_project_state([author_index_together]) + after = self.make_project_state([self.author_name]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertEqual(len(changes['testapp']), 1) + migration = changes['testapp'][0] + # Right number of actions? + self.assertEqual(len(migration.operations), 1) + # Right actions? + action = migration.operations[0] + self.assertEqual(action.__class__.__name__, "AlterIndexTogether") + self.assertEqual(action.index_together, None) + + def test_remove_unique_together(self): + author_unique_together = ModelState("testapp", "Author", [ + ("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)) + ], {"unique_together": [("id", "name")]}) + + before = self.make_project_state([author_unique_together]) + after = self.make_project_state([self.author_name]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertEqual(len(changes['testapp']), 1) + migration = changes['testapp'][0] + # Right number of actions? + self.assertEqual(len(migration.operations), 1) + # Right actions? + action = migration.operations[0] + self.assertEqual(action.__class__.__name__, "AlterUniqueTogether") + self.assertEqual(action.unique_together, None) + def test_proxy(self): "Tests that the autodetector correctly deals with proxy models" # First, we test adding a proxy model |
