summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-06-15 12:34:02 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-06-15 12:34:34 -0700
commit3ef87f664bb8b2a46546de755bfc4e158c90032f (patch)
tree6069996b70e34c31360edaaa7f427f6069240e3b /tests
parent13aa079941dcfd953ba03a83f55c8a14399d15c2 (diff)
[1.7.x] Persist non-schema-relevant Meta changes in migrations
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py15
-rw-r--r--tests/migrations/test_operations.py13
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 48c76d1bca..45687418d2 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -42,6 +42,7 @@ class AutodetectorTests(TestCase):
("publishers", models.ManyToManyField("testapp.Publisher")),
])
author_with_m2m_through = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("publishers", models.ManyToManyField("testapp.Publisher", through="testapp.Contract"))])
+ author_with_options = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True))], {"verbose_name": "Authi", "permissions": [('can_hire', 'Can hire')]})
contract = ModelState("testapp", "Contract", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("publisher", models.ForeignKey("testapp.Publisher"))])
publisher = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=100))])
publisher_with_author = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("name", models.CharField(max_length=100))])
@@ -787,3 +788,17 @@ class AutodetectorTests(TestCase):
self.assertNumberMigrations(changes, "testapp", 1)
# Right actions in right order?
self.assertOperationTypes(changes, "testapp", 0, ["RemoveField", "RemoveField", "DeleteModel", "DeleteModel"])
+
+ def test_alter_model_options(self):
+ """
+ If two models with a ForeignKey from one to the other are removed at the same time,
+ the autodetector should remove them in the correct order.
+ """
+ before = self.make_project_state([self.author_empty])
+ after = self.make_project_state([self.author_with_options])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertNumberMigrations(changes, "testapp", 1)
+ # Right actions in right order?
+ self.assertOperationTypes(changes, "testapp", 0, ["AlterModelOptions"])
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 472d7b003e..fccc6b8cd7 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -790,6 +790,19 @@ class OperationTests(MigrationTestBase):
operation.database_backwards("test_alinto", editor, new_state, project_state)
self.assertIndexNotExists("test_alinto_pony", ["pink", "weight"])
+ def test_alter_model_options(self):
+ """
+ Tests the AlterModelOptions operation.
+ """
+ project_state = self.set_up_test_model("test_almoop")
+ # Test the state alteration (no DB alteration to test)
+ operation = migrations.AlterModelOptions("Pony", {"permissions": [("can_groom", "Can groom")]})
+ new_state = project_state.clone()
+ operation.state_forwards("test_almoop", new_state)
+ self.assertEqual(len(project_state.models["test_almoop", "pony"].options.get("permissions", [])), 0)
+ 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")
+
@unittest.skipIf(sqlparse is None and connection.features.requires_sqlparse_for_splitting, "Missing sqlparse")
def test_run_sql(self):
"""