diff options
| author | Anton Baklanov <antonbaklanov@gmail.com> | 2014-02-13 16:04:19 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-02-14 20:00:39 -0500 |
| commit | 0bd92d68ade11b56124c7cdfbbfff6eb37899291 (patch) | |
| tree | 433d0368d09f43d3f99842e55a627519a697c8a5 /tests | |
| parent | f683cb90bea2afbe0ef4c011acd4ab590c37410d (diff) | |
Fixed #22035 -- reordered migration operations
Now AddField actions appear in operations list before AlterUniqueTogether
actions.
Thanks to SmileyChris for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index dca971dd8e..590858a117 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -29,6 +29,7 @@ class AutodetectorTests(TestCase): book = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("title", models.CharField(max_length=200))]) book_unique = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("title", models.CharField(max_length=200))], {"unique_together": [("author", "title")]}) book_unique_2 = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("title", models.CharField(max_length=200))], {"unique_together": [("title", "author")]}) + book_unique_3 = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("newfield", models.IntegerField()), ("author", models.ForeignKey("testapp.Author")), ("title", models.CharField(max_length=200))], {"unique_together": [("title", "newfield")]}) edition = ModelState("thirdapp", "Edition", [("id", models.AutoField(primary_key=True)), ("book", models.ForeignKey("otherapp.Book"))]) custom_user = ModelState("thirdapp", "CustomUser", [("id", models.AutoField(primary_key=True)), ("username", models.CharField(max_length=255))]) @@ -333,6 +334,24 @@ class AutodetectorTests(TestCase): self.assertEqual(action.name, "book") self.assertEqual(action.unique_together, set([("title", "author")])) + def test_add_field_and_unique_together(self): + "Tests that added fields will be created before using them in unique together" + before = self.make_project_state([self.author_empty, self.book]) + after = self.make_project_state([self.author_empty, self.book_unique_3]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertEqual(len(changes['otherapp']), 1) + # Right number of actions? + migration = changes['otherapp'][0] + self.assertEqual(len(migration.operations), 2) + # Right actions order? + action1 = migration.operations[0] + action2 = migration.operations[1] + self.assertEqual(action1.__class__.__name__, "AddField") + self.assertEqual(action2.__class__.__name__, "AlterUniqueTogether") + self.assertEqual(action2.unique_together, set([("title", "newfield")])) + def test_proxy_ignorance(self): "Tests that the autodetector correctly ignores proxy models" # First, we test adding a proxy model |
