diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-03-07 09:21:59 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-03-07 15:22:03 +0100 |
| commit | 4cccb85e292fea01b3459cd97d751ed35179a7b7 (patch) | |
| tree | 3132e647c343b8e3b900438d7b1080ddc3cb20fd /tests/forms_tests | |
| parent | 25ce177e66fb0e88a39806f5a493e03f1801775a (diff) | |
Fixed #19997 -- Added custom EMPTY_VALUES to form fields
Thanks Loic Bistuer for the report and the patch.
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' : {}}) |
