summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2017-04-07 09:44:28 +0100
committerTim Graham <timograham@gmail.com>2017-05-01 10:08:50 -0400
commit211d2bf3f21fee22c868cd39452a133ad1e16c4d (patch)
tree00296ef48c77e3e1de58cc60d8f7db38f4f726b8 /tests
parentccb3b0ee679efd7c2e2f50b2e1bcd57634eecdca (diff)
[1.11.x] Fixed #28043 -- Prevented AddIndex and RemoveIndex from mutating model state.
Backport of 63afe3a2bfaf97fecff6641137a85296029d5b73 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_operations.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index e1daabe8b5..dd8aff4ca8 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1491,6 +1491,29 @@ class OperationTests(OperationTestBase):
self.unapply_operations("test_rmin", project_state, operations=operations)
self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
+ def test_add_index_state_forwards(self):
+ project_state = self.set_up_test_model('test_adinsf')
+ index = models.Index(fields=['pink'], name='test_adinsf_pony_pink_idx')
+ old_model = project_state.apps.get_model('test_adinsf', 'Pony')
+ new_state = project_state.clone()
+
+ operation = migrations.AddIndex('Pony', index)
+ operation.state_forwards('test_adinsf', new_state)
+ new_model = new_state.apps.get_model('test_adinsf', 'Pony')
+ self.assertIsNot(old_model, new_model)
+
+ def test_remove_index_state_forwards(self):
+ project_state = self.set_up_test_model('test_rminsf')
+ index = models.Index(fields=['pink'], name='test_rminsf_pony_pink_idx')
+ migrations.AddIndex('Pony', index).state_forwards('test_rminsf', project_state)
+ old_model = project_state.apps.get_model('test_rminsf', 'Pony')
+ new_state = project_state.clone()
+
+ operation = migrations.RemoveIndex('Pony', 'test_rminsf_pony_pink_idx')
+ operation.state_forwards('test_rminsf', new_state)
+ new_model = new_state.apps.get_model('test_rminsf', 'Pony')
+ self.assertIsNot(old_model, new_model)
+
def test_alter_field_with_index(self):
"""
Test AlterField operation with an index to ensure indexes created via