summaryrefslogtreecommitdiff
path: root/tests/migrations/test_autodetector.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/migrations/test_autodetector.py')
-rw-r--r--tests/migrations/test_autodetector.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 74892bbf3d..4c91659ca8 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -2793,6 +2793,43 @@ class AutodetectorTests(BaseAutodetectorTests):
["CreateModel", "AddField", "AddConstraint"],
)
+ def test_add_constraints_with_dict_keys(self):
+ book_types = {"F": "Fantasy", "M": "Mystery"}
+ book_with_type = ModelState(
+ "testapp",
+ "Book",
+ [
+ ("id", models.AutoField(primary_key=True)),
+ ("type", models.CharField(max_length=1)),
+ ],
+ {
+ "constraints": [
+ models.CheckConstraint(
+ check=models.Q(type__in=book_types.keys()),
+ name="book_type_check",
+ ),
+ ],
+ },
+ )
+ book_with_resolved_type = ModelState(
+ "testapp",
+ "Book",
+ [
+ ("id", models.AutoField(primary_key=True)),
+ ("type", models.CharField(max_length=1)),
+ ],
+ {
+ "constraints": [
+ models.CheckConstraint(
+ check=models.Q(("type__in", tuple(book_types))),
+ name="book_type_check",
+ ),
+ ],
+ },
+ )
+ changes = self.get_changes([book_with_type], [book_with_resolved_type])
+ self.assertEqual(len(changes), 0)
+
def test_add_index_with_new_model(self):
book_with_index_title_and_pony = ModelState(
"otherapp",