mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
[1.7.x] Fixed #22568: Better proxy model support in migrations
This commit is contained in:
@@ -37,7 +37,7 @@ class OperationTests(MigrationTestBase):
|
||||
with connection.schema_editor() as editor:
|
||||
return migration.unapply(project_state, editor)
|
||||
|
||||
def set_up_test_model(self, app_label, second_model=False, third_model=False, related_model=False, mti_model=False):
|
||||
def set_up_test_model(self, app_label, second_model=False, third_model=False, related_model=False, mti_model=False, proxy_model=False):
|
||||
"""
|
||||
Creates a test model state and database table.
|
||||
"""
|
||||
@@ -112,6 +112,13 @@ class OperationTests(MigrationTestBase):
|
||||
],
|
||||
bases=['%s.Pony' % app_label],
|
||||
))
|
||||
if proxy_model:
|
||||
operations.append(migrations.CreateModel(
|
||||
"ProxyPony",
|
||||
fields=[],
|
||||
options={"proxy": True},
|
||||
bases=['%s.Pony' % app_label],
|
||||
))
|
||||
|
||||
return self.apply_operations(app_label, ProjectState(), operations)
|
||||
|
||||
@@ -221,6 +228,34 @@ class OperationTests(MigrationTestBase):
|
||||
operation.database_backwards("test_crmoih", editor, new_state, project_state)
|
||||
self.assertTableNotExists("test_crmoih_shetlandpony")
|
||||
|
||||
def test_create_proxy_model(self):
|
||||
"""
|
||||
Tests that CreateModel ignores proxy models.
|
||||
"""
|
||||
project_state = self.set_up_test_model("test_crprmo")
|
||||
# Test the state alteration
|
||||
operation = migrations.CreateModel(
|
||||
"ProxyPony",
|
||||
[],
|
||||
options = {"proxy": True},
|
||||
bases = ("test_crprmo.Pony", ),
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_crprmo", new_state)
|
||||
self.assertIn(("test_crprmo", "proxypony"), new_state.models)
|
||||
# Test the database alteration
|
||||
self.assertTableNotExists("test_crprmo_proxypony")
|
||||
self.assertTableExists("test_crprmo_pony")
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_forwards("test_crprmo", editor, project_state, new_state)
|
||||
self.assertTableNotExists("test_crprmo_proxypony")
|
||||
self.assertTableExists("test_crprmo_pony")
|
||||
# And test reversal
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_backwards("test_crprmo", editor, new_state, project_state)
|
||||
self.assertTableNotExists("test_crprmo_proxypony")
|
||||
self.assertTableExists("test_crprmo_pony")
|
||||
|
||||
def test_delete_model(self):
|
||||
"""
|
||||
Tests the DeleteModel operation.
|
||||
@@ -241,6 +276,30 @@ class OperationTests(MigrationTestBase):
|
||||
operation.database_backwards("test_dlmo", editor, new_state, project_state)
|
||||
self.assertTableExists("test_dlmo_pony")
|
||||
|
||||
def test_delete_proxy_model(self):
|
||||
"""
|
||||
Tests the DeleteModel operation ignores proxy models.
|
||||
"""
|
||||
project_state = self.set_up_test_model("test_dlprmo", proxy_model=True)
|
||||
# Test the state alteration
|
||||
operation = migrations.DeleteModel("ProxyPony")
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_dlprmo", new_state)
|
||||
self.assertIn(("test_dlprmo", "proxypony"), project_state.models)
|
||||
self.assertNotIn(("test_dlprmo", "proxypony"), new_state.models)
|
||||
# Test the database alteration
|
||||
self.assertTableExists("test_dlprmo_pony")
|
||||
self.assertTableNotExists("test_dlprmo_proxypony")
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_forwards("test_dlprmo", editor, project_state, new_state)
|
||||
self.assertTableExists("test_dlprmo_pony")
|
||||
self.assertTableNotExists("test_dlprmo_proxypony")
|
||||
# And test reversal
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_backwards("test_dlprmo", editor, new_state, project_state)
|
||||
self.assertTableExists("test_dlprmo_pony")
|
||||
self.assertTableNotExists("test_dlprmo_proxypony")
|
||||
|
||||
def test_rename_model(self):
|
||||
"""
|
||||
Tests the RenameModel operation.
|
||||
|
||||
Reference in New Issue
Block a user