summaryrefslogtreecommitdiff
path: root/tests/model_fields/test_integerfield.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_fields/test_integerfield.py')
-rw-r--r--tests/model_fields/test_integerfield.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/model_fields/test_integerfield.py b/tests/model_fields/test_integerfield.py
index 0d91cff9eb..34966304fb 100644
--- a/tests/model_fields/test_integerfield.py
+++ b/tests/model_fields/test_integerfield.py
@@ -318,3 +318,18 @@ class ValidationTests(SimpleTestCase):
f.clean("A", None)
with self.assertRaises(ValidationError):
f.clean("3", None)
+
+ def test_callable_choices(self):
+ def get_choices():
+ return {i: str(i) for i in range(3)}
+
+ f = models.IntegerField(choices=get_choices)
+
+ for i in get_choices():
+ with self.subTest(i=i):
+ self.assertEqual(i, f.clean(i, None))
+
+ with self.assertRaises(ValidationError):
+ f.clean("A", None)
+ with self.assertRaises(ValidationError):
+ f.clean("3", None)