summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorSenko Rasic <senko.rasic@dobarkod.hr>2013-05-18 13:44:27 +0200
committerSenko Rasic <senko.rasic@dobarkod.hr>2013-05-18 13:44:27 +0200
commit493aca453aa94f160764d9a89c8043f7c9a67a78 (patch)
treef5793baf8c86fc4ebbc5c28df58f344acf60bb45 /tests/forms_tests
parent566e284c565a9ea95d81756c6b1f94dfa63fc61b (diff)
Fixed #11160 - Ensure full_clean is called from non_form_errors
Updated FormSet.non_form_errors() to ensure full_clean() has been called before returning the errors.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_formsets.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index 4ac3c5ecf1..31adb921ba 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -972,6 +972,20 @@ class FormsFormsetTestCase(TestCase):
finally:
formsets.DEFAULT_MAX_NUM = _old_DEFAULT_MAX_NUM
+ def test_non_form_errors_run_full_clean(self):
+ # Regression test for #11160
+ # If non_form_errors() is called without calling is_valid() first,
+ # it should ensure that full_clean() is called.
+ class BaseCustomFormSet(BaseFormSet):
+ def clean(self):
+ raise ValidationError("This is a non-form error")
+
+ ChoiceFormSet = formset_factory(Choice, formset=BaseCustomFormSet)
+ formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
+ self.assertTrue(isinstance(formset.non_form_errors(), ErrorList))
+ self.assertEqual(list(formset.non_form_errors()),
+ ['This is a non-form error'])
+
data = {
'choices-TOTAL_FORMS': '1', # the number of forms rendered