summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests/test_ordinary_fields.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2025-11-19 08:22:44 +0100
committerGitHub <noreply@github.com>2025-11-19 08:22:44 +0100
commit97acd4d2f92eef8c285bac070d437bf0fd52e071 (patch)
tree62de2c4f5299318d8cffbf67d544f239c1d7fc07 /tests/invalid_models_tests/test_ordinary_fields.py
parente05f2a75695b5f5faa7682d4053db4776d4d6f93 (diff)
Fixed #26609 -- Extended fields.E004 system check for unordered iterables.
Co-authored-by: Karl Wooster <karl.wooster@alleima.com>
Diffstat (limited to 'tests/invalid_models_tests/test_ordinary_fields.py')
-rw-r--r--tests/invalid_models_tests/test_ordinary_fields.py42
1 files changed, 38 insertions, 4 deletions
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py
index 2c2653a538..04c18d7ddd 100644
--- a/tests/invalid_models_tests/test_ordinary_fields.py
+++ b/tests/invalid_models_tests/test_ordinary_fields.py
@@ -199,8 +199,8 @@ class CharFieldTests(TestCase):
field.check(),
[
Error(
- "'choices' must be a mapping (e.g. a dictionary) or an iterable "
- "(e.g. a list or tuple).",
+ "'choices' must be a mapping (e.g. a dictionary) or an "
+ "ordered iterable (e.g. a list or tuple, but not a set).",
obj=field,
id="fields.E004",
),
@@ -906,8 +906,42 @@ class IntegerFieldTests(SimpleTestCase):
field.check(),
[
Error(
- "'choices' must be a mapping (e.g. a dictionary) or an iterable "
- "(e.g. a list or tuple).",
+ "'choices' must be a mapping (e.g. a dictionary) or an "
+ "ordered iterable (e.g. a list or tuple, but not a set).",
+ obj=field,
+ id="fields.E004",
+ ),
+ ],
+ )
+
+ def test_unordered_choices_set(self):
+ class Model(models.Model):
+ field = models.IntegerField(choices={1, 2, 3})
+
+ field = Model._meta.get_field("field")
+ self.assertEqual(
+ field.check(),
+ [
+ Error(
+ "'choices' must be a mapping (e.g. a dictionary) or an "
+ "ordered iterable (e.g. a list or tuple, but not a set).",
+ obj=field,
+ id="fields.E004",
+ ),
+ ],
+ )
+
+ def test_unordered_choices_frozenset(self):
+ class Model(models.Model):
+ field = models.IntegerField(choices=frozenset({1, 2, 3}))
+
+ field = Model._meta.get_field("field")
+ self.assertEqual(
+ field.check(),
+ [
+ Error(
+ "'choices' must be a mapping (e.g. a dictionary) or an "
+ "ordered iterable (e.g. a list or tuple, but not a set).",
obj=field,
id="fields.E004",
),