summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-01-10 15:18:06 +0100
committerMarkus Holtermann <info@markusholtermann.eu>2015-01-10 23:14:15 +0100
commitfdc2cc948725866212a9bcc97b9b7cf21bb49b90 (patch)
treeabb7d671677378c9b2265ae76d6a595074a968b4 /tests
parentd89019a84d2dd314d3764dbd06ba854640db9b80 (diff)
Fixed #24110 -- Rewrote migration unapply to preserve intermediate states
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_operations.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 4f46d1a015..a491d9c280 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -465,27 +465,33 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.RenameModel("Pony", "Horse")
self.assertEqual(operation.describe(), "Rename model Pony to Horse")
- new_state = project_state.clone()
- operation.state_forwards("test_rnmo", new_state)
- self.assertNotIn(("test_rnmo", "pony"), new_state.models)
- self.assertIn(("test_rnmo", "horse"), new_state.models)
- # Remember, RenameModel also repoints all incoming FKs and M2Ms
- self.assertEqual("test_rnmo.Horse", new_state.models["test_rnmo", "rider"].fields[1][1].rel.to)
- # Test the database alteration
+ # Test initial state and database
+ self.assertIn(("test_rnmo", "pony"), project_state.models)
+ self.assertNotIn(("test_rnmo", "horse"), project_state.models)
self.assertTableExists("test_rnmo_pony")
self.assertTableNotExists("test_rnmo_horse")
if connection.features.supports_foreign_keys:
self.assertFKExists("test_rnmo_rider", ["pony_id"], ("test_rnmo_pony", "id"))
self.assertFKNotExists("test_rnmo_rider", ["pony_id"], ("test_rnmo_horse", "id"))
- with connection.schema_editor() as editor:
- operation.database_forwards("test_rnmo", editor, project_state, new_state)
+ # Migrate forwards
+ new_state = project_state.clone()
+ new_state = self.apply_operations("test_rnmo", new_state, [operation])
+ # Test new state and database
+ self.assertNotIn(("test_rnmo", "pony"), new_state.models)
+ self.assertIn(("test_rnmo", "horse"), new_state.models)
+ # RenameModel also repoints all incoming FKs and M2Ms
+ self.assertEqual("test_rnmo.Horse", new_state.models["test_rnmo", "rider"].fields[1][1].rel.to)
self.assertTableNotExists("test_rnmo_pony")
self.assertTableExists("test_rnmo_horse")
if connection.features.supports_foreign_keys:
self.assertFKNotExists("test_rnmo_rider", ["pony_id"], ("test_rnmo_pony", "id"))
self.assertFKExists("test_rnmo_rider", ["pony_id"], ("test_rnmo_horse", "id"))
- # And test reversal
- self.unapply_operations("test_rnmo", project_state, [operation])
+ # Migrate backwards
+ original_state = self.unapply_operations("test_rnmo", project_state, [operation])
+ # Test original state and database
+ self.assertIn(("test_rnmo", "pony"), original_state.models)
+ self.assertNotIn(("test_rnmo", "horse"), original_state.models)
+ self.assertEqual("Pony", original_state.models["test_rnmo", "rider"].fields[1][1].rel.to)
self.assertTableExists("test_rnmo_pony")
self.assertTableNotExists("test_rnmo_horse")
if connection.features.supports_foreign_keys: