summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-08-12 12:49:20 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-08-12 12:49:20 -0700
commit8f9862cd4d0e9706babf947079739fd476455df7 (patch)
tree9200f85665ab95c8b29ba0aebb5d5db633b20d3b /tests
parent6745b6fd7a57c493d9e050dc76799cef810bed01 (diff)
Fixed #23275: Unmanaged models kept by autodetector, ignored by ops
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py22
-rw-r--r--tests/migrations/test_operations.py29
2 files changed, 39 insertions, 12 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 73e89bbec2..86f8ce3982 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -639,30 +639,28 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, "testapp", 0, 0, name="AuthorProxy")
self.assertOperationAttributes(changes, "testapp", 0, 1, name="AuthorProxy", options={})
- def test_unmanaged_ignorance(self):
- "Tests that the autodetector correctly ignores managed models"
+ def test_unmanaged(self):
+ "Tests that the autodetector correctly deals with managed models"
# First, we test adding an unmanaged model
before = self.make_project_state([self.author_empty])
after = self.make_project_state([self.author_empty, self.author_unmanaged])
autodetector = MigrationAutodetector(before, after)
changes = autodetector._detect_changes()
# Right number of migrations?
- self.assertEqual(len(changes), 0)
-
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0, name="AuthorUnmanaged")
+ self.assertEqual(changes['testapp'][0].operations[0].options['managed'], False)
# Now, we test turning an unmanaged model into a managed model
before = self.make_project_state([self.author_empty, self.author_unmanaged])
after = self.make_project_state([self.author_empty, self.author_unmanaged_managed])
autodetector = MigrationAutodetector(before, after)
changes = autodetector._detect_changes()
# Right number of migrations?
- self.assertEqual(len(changes['testapp']), 1)
- # Right number of actions?
- migration = changes['testapp'][0]
- self.assertEqual(len(migration.operations), 1)
- # Right action?
- action = migration.operations[0]
- self.assertEqual(action.__class__.__name__, "CreateModel")
- self.assertEqual(action.name, "AuthorUnmanaged")
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, 'testapp', 0, ["DeleteModel", "CreateModel"])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0, name="AuthorUnmanaged")
+ self.assertOperationAttributes(changes, 'testapp', 0, 1, name="AuthorUnmanaged")
@override_settings(AUTH_USER_MODEL="thirdapp.CustomUser")
def test_swappable(self):
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index fb59cf63bc..760e06040c 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -326,6 +326,35 @@ class OperationTests(OperationTestBase):
self.assertTableNotExists("test_crprmo_proxypony")
self.assertTableExists("test_crprmo_pony")
+ def test_create_unmanaged_model(self):
+ """
+ Tests that CreateModel ignores unmanaged models.
+ """
+ project_state = self.set_up_test_model("test_crummo")
+ # Test the state alteration
+ operation = migrations.CreateModel(
+ "UnmanagedPony",
+ [],
+ options={"proxy": True},
+ bases=("test_crummo.Pony", ),
+ )
+ self.assertEqual(operation.describe(), "Create proxy model UnmanagedPony")
+ new_state = project_state.clone()
+ operation.state_forwards("test_crummo", new_state)
+ self.assertIn(("test_crummo", "unmanagedpony"), new_state.models)
+ # Test the database alteration
+ self.assertTableNotExists("test_crummo_unmanagedpony")
+ self.assertTableExists("test_crummo_pony")
+ with connection.schema_editor() as editor:
+ operation.database_forwards("test_crummo", editor, project_state, new_state)
+ self.assertTableNotExists("test_crummo_unmanagedpony")
+ self.assertTableExists("test_crummo_pony")
+ # And test reversal
+ with connection.schema_editor() as editor:
+ operation.database_backwards("test_crummo", editor, new_state, project_state)
+ self.assertTableNotExists("test_crummo_unmanagedpony")
+ self.assertTableExists("test_crummo_pony")
+
def test_delete_model(self):
"""
Tests the DeleteModel operation.