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:04:46 -0400 |
| commit | f1428dc796817a241d49319122663129d78ca853 (patch) | |
| tree | cbad79e402d41847b18545cb28a654979a5f18e5 /tests | |
| parent | 8dcc7810f07e2ce76ebee50c70a5c16f1bc9edec (diff) | |
[1.7.x] Fixed #22903 -- Fixed migration generation if index_together or unique_together is removed from a model.
Backport of e0cd07ec2f from master
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 0091ac3963..6e52ddf690 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -565,6 +565,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 |
