Merge pull request #1094 from senko/ticket_11160

Fixed #11160: Formset non_form_errors returns ErrorList() if is_valid is not called
This commit is contained in:
Andrew Godwin 2013-05-19 03:56:14 -07:00
commit 04e0fc029f
3 changed files with 22 additions and 4 deletions

View file

@ -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