Fixed #31262 -- Added support for mappings on model fields and ChoiceField's choices.

This commit is contained in:
Nick Pope 2023-08-31 02:57:40 +01:00 committed by GitHub
parent 68a8996bdf
commit 500e01073a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 822 additions and 249 deletions

View file

@ -279,6 +279,14 @@ class ValidationTests(SimpleTestCase):
f = models.IntegerField(choices=(("group", ((10, "A"), (20, "B"))), (30, "C")))
self.assertEqual(10, f.clean(10, None))
def test_choices_validation_supports_named_groups_dicts(self):
f = models.IntegerField(choices={"group": ((10, "A"), (20, "B")), 30: "C"})
self.assertEqual(10, f.clean(10, None))
def test_choices_validation_supports_named_groups_nested_dicts(self):
f = models.IntegerField(choices={"group": {10: "A", 20: "B"}, 30: "C"})
self.assertEqual(10, f.clean(10, None))
def test_nullable_integerfield_raises_error_with_blank_false(self):
f = models.IntegerField(null=True, blank=False)
with self.assertRaises(ValidationError):