summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-12-23 12:27:49 -0500
committerTim Graham <timograham@gmail.com>2014-12-23 14:26:56 -0500
commit51ea30a43bafad40b4a24ad0be346796a9c7ab6a (patch)
tree673def0025a88209579282096be4c2603faa5f88 /tests
parentac098867c004b7336aac30d0689e70fbd73a7306 (diff)
[1.7.x] Fixed #24037 -- Prevented data loss possibility when changing Meta.managed.
The migrations autodetector now issues AlterModelOptions operations for Meta.managed changes instead of DeleteModel + CreateModel. Thanks iambibhas for the report and Simon and Markus for review. Backport of 061caa5b386681dc7bdef16918873043224a299c from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 38771f16ac..8beda8e552 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1021,7 +1021,7 @@ class AutodetectorTests(TestCase):
# The field name the FK on the book model points to
self.assertEqual(changes['otherapp'][0].operations[0].fields[2][1].rel.field_name, 'pk_field')
- def test_unmanaged(self):
+ def test_unmanaged_create(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])
@@ -1031,9 +1031,10 @@ class AutodetectorTests(TestCase):
# Right number/type of migrations?
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)
+ self.assertOperationAttributes(changes, 'testapp', 0, 0,
+ name="AuthorUnmanaged", options={"managed": False})
+ def test_unmanaged_to_managed(self):
# 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])
@@ -1041,9 +1042,21 @@ class AutodetectorTests(TestCase):
changes = autodetector._detect_changes()
# Right number/type of migrations?
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")
+ self.assertOperationTypes(changes, 'testapp', 0, ["AlterModelOptions"])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0,
+ name="authorunmanaged", options={})
+
+ def test_managed_to_unmanaged(self):
+ # Now, we turn managed to unmanaged.
+ before = self.make_project_state([self.author_empty, self.author_unmanaged_managed])
+ after = self.make_project_state([self.author_empty, self.author_unmanaged])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number/type of migrations?
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, "testapp", 0, ["AlterModelOptions"])
+ self.assertOperationAttributes(changes, "testapp", 0, 0,
+ name="authorunmanaged", options={"managed": False})
def test_unmanaged_custom_pk(self):
"""