summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-07-28 10:47:28 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-07-28 10:47:28 -0700
commitd6e73a876d77e889efe839345d39690a7004e2f4 (patch)
treeb9b31188450208d950f9ddfbd49c0cec2c2e89db /tests
parentcb60d22bd94738174440f8d60a04c3d9c38636c9 (diff)
Fixed #23121: AlterModelOptions operation not changing state right
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py7
-rw-r--r--tests/migrations/test_operations.py26
2 files changed, 28 insertions, 5 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 8b13269d77..e750fc9194 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -897,6 +897,13 @@ class AutodetectorTests(TestCase):
self.assertNumberMigrations(changes, "testapp", 1)
# Right actions in right order?
self.assertOperationTypes(changes, "testapp", 0, ["AlterModelOptions"])
+ # Changing them back to empty should also make a change
+ before = self.make_project_state([self.author_with_options])
+ after = self.make_project_state([self.author_empty])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ self.assertNumberMigrations(changes, "testapp", 1)
+ self.assertOperationTypes(changes, "testapp", 0, ["AlterModelOptions"])
def test_alter_model_options_proxy(self):
"""
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 815838d826..769d0be417 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -46,7 +46,7 @@ class OperationTestBase(MigrationTestBase):
operation.state_forwards(app_label, new_state)
return project_state, new_state
- def set_up_test_model(self, app_label, second_model=False, third_model=False, related_model=False, mti_model=False, proxy_model=False, unique_together=False):
+ def set_up_test_model(self, app_label, second_model=False, third_model=False, related_model=False, mti_model=False, proxy_model=False, unique_together=False, options=False):
"""
Creates a test model state and database table.
"""
@@ -76,6 +76,12 @@ class OperationTestBase(MigrationTestBase):
except DatabaseError:
pass
# Make the "current" state
+ model_options = {
+ "swappable": "TEST_SWAP_MODEL",
+ "unique_together": [["pink", "weight"]] if unique_together else [],
+ }
+ if options:
+ model_options["permissions"] = [("can_groom", "Can groom")]
operations = [migrations.CreateModel(
"Pony",
[
@@ -83,10 +89,7 @@ class OperationTestBase(MigrationTestBase):
("pink", models.IntegerField(default=3)),
("weight", models.FloatField()),
],
- options={
- "swappable": "TEST_SWAP_MODEL",
- "unique_together": [["pink", "weight"]] if unique_together else [],
- },
+ options=model_options,
)]
if second_model:
operations.append(migrations.CreateModel(
@@ -975,6 +978,19 @@ class OperationTests(OperationTestBase):
self.assertEqual(len(new_state.models["test_almoop", "pony"].options.get("permissions", [])), 1)
self.assertEqual(new_state.models["test_almoop", "pony"].options["permissions"][0][0], "can_groom")
+ def test_alter_model_options_emptying(self):
+ """
+ Tests that the AlterModelOptions operation removes keys from the dict (#23121)
+ """
+ project_state = self.set_up_test_model("test_almoop", options=True)
+ # Test the state alteration (no DB alteration to test)
+ operation = migrations.AlterModelOptions("Pony", {})
+ self.assertEqual(operation.describe(), "Change Meta options on Pony")
+ new_state = project_state.clone()
+ operation.state_forwards("test_almoop", new_state)
+ self.assertEqual(len(project_state.models["test_almoop", "pony"].options.get("permissions", [])), 1)
+ self.assertEqual(len(new_state.models["test_almoop", "pony"].options.get("permissions", [])), 0)
+
def test_alter_order_with_respect_to(self):
"""
Tests the AlterOrderWithRespectTo operation.