summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
authorSimon Charette <charettes@users.noreply.github.com>2018-07-25 12:07:42 -0400
committerTim Graham <timograham@gmail.com>2018-07-25 12:07:41 -0400
commitdc1dcad0f54677bfdbcf187bbcb8eca5f73b6fca (patch)
tree40dd9dcdc7fb93ea0f28b1875c0aa14f2facee75 /tests/migrations
parentac25dd1f8d48accc765c05aebb47c427e51f3255 (diff)
Refs #24424 -- Added regression tests for MTI-inheritance model removal.
The issue was fixed as a side effect of implementing RemoveField's reduction of DeleteModel to a DeleteModel in ad82900ad94ed4bbad050b9993373dafbe66b610.
Diffstat (limited to 'tests/migrations')
-rw-r--r--tests/migrations/test_autodetector.py10
-rw-r--r--tests/migrations/test_operations.py23
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 02b95b5458..b3232c0f59 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -2354,3 +2354,13 @@ class AutodetectorTests(TestCase):
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ["AddField", "AddField"])
self.assertOperationAttributes(changes, 'testapp', 0, 0)
+
+ def test_mti_inheritance_model_removal(self):
+ Animal = ModelState('app', 'Animal', [
+ ("id", models.AutoField(primary_key=True)),
+ ])
+ Dog = ModelState('app', 'Dog', [], bases=('app.Animal',))
+ changes = self.get_changes([Animal, Dog], [Animal])
+ self.assertNumberMigrations(changes, 'app', 1)
+ self.assertOperationTypes(changes, 'app', 0, ['DeleteModel'])
+ self.assertOperationAttributes(changes, 'app', 0, 0, name='Dog')
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 142330127b..9da67fad7f 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -588,6 +588,29 @@ class OperationTests(OperationTestBase):
self.assertTableExists("test_dlprmo_pony")
self.assertTableNotExists("test_dlprmo_proxypony")
+ def test_delete_mti_model(self):
+ project_state = self.set_up_test_model('test_dlmtimo', mti_model=True)
+ # Test the state alteration
+ operation = migrations.DeleteModel('ShetlandPony')
+ new_state = project_state.clone()
+ operation.state_forwards('test_dlmtimo', new_state)
+ self.assertIn(('test_dlmtimo', 'shetlandpony'), project_state.models)
+ self.assertNotIn(('test_dlmtimo', 'shetlandpony'), new_state.models)
+ # Test the database alteration
+ self.assertTableExists('test_dlmtimo_pony')
+ self.assertTableExists('test_dlmtimo_shetlandpony')
+ self.assertColumnExists('test_dlmtimo_shetlandpony', 'pony_ptr_id')
+ with connection.schema_editor() as editor:
+ operation.database_forwards('test_dlmtimo', editor, project_state, new_state)
+ self.assertTableExists('test_dlmtimo_pony')
+ self.assertTableNotExists('test_dlmtimo_shetlandpony')
+ # And test reversal
+ with connection.schema_editor() as editor:
+ operation.database_backwards('test_dlmtimo', editor, new_state, project_state)
+ self.assertTableExists('test_dlmtimo_pony')
+ self.assertTableExists('test_dlmtimo_shetlandpony')
+ self.assertColumnExists('test_dlmtimo_shetlandpony', 'pony_ptr_id')
+
def test_rename_model(self):
"""
Tests the RenameModel operation.