summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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",
),