1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Massive migration optimiser improvements + RenameModel opn

This commit is contained in:
Andrew Godwin
2013-11-06 13:47:58 +00:00
parent 8265323c91
commit 106b019dc9
7 changed files with 520 additions and 19 deletions

View File

@@ -100,6 +100,30 @@ class OperationTests(MigrationTestBase):
operation.database_backwards("test_dlmo", editor, new_state, project_state)
self.assertTableExists("test_dlmo_pony")
def test_rename_model(self):
"""
Tests the RenameModel operation.
"""
project_state = self.set_up_test_model("test_rnmo")
# Test the state alteration
operation = migrations.RenameModel("Pony", "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)
# Test the database alteration
self.assertTableExists("test_rnmo_pony")
self.assertTableNotExists("test_rnmo_horse")
with connection.schema_editor() as editor:
operation.database_forwards("test_rnmo", editor, project_state, new_state)
self.assertTableNotExists("test_rnmo_pony")
self.assertTableExists("test_rnmo_horse")
# And test reversal
with connection.schema_editor() as editor:
operation.database_backwards("test_rnmo", editor, new_state, project_state)
self.assertTableExists("test_dlmo_pony")
self.assertTableNotExists("test_rnmo_horse")
def test_add_field(self):
"""
Tests the AddField operation.