1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Added IntegerField tests for checks for invalid choices.

This commit is contained in:
Nick Pope 2023-08-08 18:55:10 +02:00 committed by Mariusz Felisiak
parent 5aa4c0b675
commit aa3cb3f372

View File

@ -845,6 +845,41 @@ class IntegerFieldTests(SimpleTestCase):
],
)
def test_non_iterable_choices(self):
class Model(models.Model):
field = models.IntegerField(choices=123)
field = Model._meta.get_field("field")
self.assertEqual(
field.check(),
[
Error(
"'choices' must be an iterable (e.g., a list or tuple).",
obj=field,
id="fields.E004",
),
],
)
def test_non_iterable_choices_number(self):
"""An integer isn't a valid choice pair."""
class Model(models.Model):
field = models.IntegerField(choices=[123])
field = Model._meta.get_field("field")
self.assertEqual(
field.check(),
[
Error(
"'choices' must be an iterable containing (actual value, human "
"readable name) tuples.",
obj=field,
id="fields.E005",
),
],
)
@isolate_apps("invalid_models_tests")
class TimeFieldTests(SimpleTestCase):