diff options
Diffstat (limited to 'tests/forms_tests')
| -rw-r--r-- | tests/forms_tests/tests/forms.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/forms.py b/tests/forms_tests/tests/forms.py index f856e30d33..9cf217b86b 100644 --- a/tests/forms_tests/tests/forms.py +++ b/tests/forms_tests/tests/forms.py @@ -1797,3 +1797,23 @@ class FormsTestCase(TestCase): form = NameForm(data={'name' : ['fname', 'lname']}) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data, {'name' : 'fname lname'}) + + def test_custom_empty_values(self): + """ + Test that form fields can customize what is considered as an empty value + for themselves (#19997). + """ + class CustomJSONField(CharField): + empty_values = [None, ''] + def to_python(self, value): + # Fake json.loads + if value == '{}': + return {} + return super(CustomJSONField, self).to_python(value) + + class JSONForm(forms.Form): + json = CustomJSONField() + + form = JSONForm(data={'json': '{}'}); + form.full_clean() + self.assertEqual(form.cleaned_data, {'json' : {}}) |
