diff options
| author | Andreas Hug <hello@foonicorn.com> | 2012-12-06 20:00:56 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-12-06 20:05:16 +0100 |
| commit | 67bddc0b7b6468abe875f30e4b70560787b5eb5b (patch) | |
| tree | b6db0267656f34289fc4627159fe8adfebec2ff4 /tests | |
| parent | e9301ae451f84b06687d27af0a43bcb986054f63 (diff) | |
[1.5.x] Fixed #18574 -- Make BaseFormSet.is_valid call its underlying forms' is_valid
Thanks Simon Charette for the report and the initial patch.
Backport of 66dfcc10b from master.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/forms/tests/formsets.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py index b3ceee551b..bf893c4c1d 100644 --- a/tests/regressiontests/forms/tests/formsets.py +++ b/tests/regressiontests/forms/tests/formsets.py @@ -856,6 +856,27 @@ class FormsFormsetTestCase(TestCase): formset = FavoriteDrinksFormSet(error_class=CustomErrorList) self.assertEqual(formset.forms[0].error_class, CustomErrorList) + def test_formset_calls_forms_is_valid(self): + # Regression tests for #18574 -- make sure formsets call + # is_valid() on each form. + + class AnotherChoice(Choice): + def is_valid(self): + self.is_valid_called = True + return super(AnotherChoice, self).is_valid() + + AnotherChoiceFormSet = formset_factory(AnotherChoice) + data = { + 'choices-TOTAL_FORMS': '1', # number of forms rendered + 'choices-INITIAL_FORMS': '0', # number of forms with initial data + 'choices-MAX_NUM_FORMS': '0', # max number of forms + 'choices-0-choice': 'Calexico', + 'choices-0-votes': '100', + } + formset = AnotherChoiceFormSet(data, auto_id=False, prefix='choices') + self.assertTrue(formset.is_valid()) + self.assertTrue(all([form.is_valid_called for form in formset.forms])) + data = { 'choices-TOTAL_FORMS': '1', # the number of forms rendered |
