diff options
| author | Claude Paroz <claude@2xlibre.net> | 2020-10-17 16:17:00 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-17 21:01:54 +0200 |
| commit | 8caf524a1dd35d57827dff6950460f9d8b9d2dab (patch) | |
| tree | fa3a626a6c9617ea573efa58d5a8e1ee401f0f5a /tests/forms_tests | |
| parent | be3ce38656f9b5799e15b92cec30392132e104d1 (diff) | |
[3.1.x] Fixed #32110 -- Doc'd and tested enumerations for ChoiceField.choices.
Backport of 7f85498eef1d8fcc52e4fb70df8041f5452d405a from master
Diffstat (limited to 'tests/forms_tests')
| -rw-r--r-- | tests/forms_tests/field_tests/test_choicefield.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/forms_tests/field_tests/test_choicefield.py b/tests/forms_tests/field_tests/test_choicefield.py index cdb264b36c..f25e2cedfd 100644 --- a/tests/forms_tests/field_tests/test_choicefield.py +++ b/tests/forms_tests/field_tests/test_choicefield.py @@ -1,4 +1,5 @@ from django.core.exceptions import ValidationError +from django.db import models from django.forms import ChoiceField, Form from django.test import SimpleTestCase @@ -87,3 +88,14 @@ class ChoiceFieldTest(FormFieldAssertionsMixin, SimpleTestCase): '<select id="id_f" name="f" disabled><option value="J">John</option>' '<option value="P">Paul</option></select>' ) + + def test_choicefield_enumeration(self): + class FirstNames(models.TextChoices): + JOHN = 'J', 'John' + PAUL = 'P', 'Paul' + + f = ChoiceField(choices=FirstNames.choices) + self.assertEqual(f.clean('J'), 'J') + msg = "'Select a valid choice. 3 is not one of the available choices.'" + with self.assertRaisesMessage(ValidationError, msg): + f.clean('3') |
