summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-04-28 09:32:40 -0400
committerTim Graham <timograham@gmail.com>2017-04-28 09:32:52 -0400
commite93135b067c4f2bfe423e605bdfe0786eaecaef2 (patch)
treed3d470529b88f9d70f750f5075af313a2713ee7f /tests
parentba85929188ddcf8ba2e25c6dbeb8130a002e7676 (diff)
[1.11.x] Fixed #28130 -- Fixed formset min_num validation with initial, unchanged forms.
Regression in f5c6295797b8332134fd89e0209a18a1d1d45e0c. Backport of f04a40491764bdc9a2ebbfc03fa7be424fb3ce63 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/forms_tests/tests/test_formsets.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index 29f0befc18..1c431e5e22 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -405,6 +405,31 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertFalse(formset.is_valid())
self.assertEqual(formset.non_form_errors(), ['Please submit 3 or more forms.'])
+ def test_formset_validate_min_unchanged_forms(self):
+ """
+ min_num validation doesn't consider unchanged forms with initial data
+ as "empty".
+ """
+ initial = [
+ {'choice': 'Zero', 'votes': 0},
+ {'choice': 'One', 'votes': 0},
+ ]
+ data = {
+ 'choices-TOTAL_FORMS': '2',
+ 'choices-INITIAL_FORMS': '2',
+ 'choices-MIN_NUM_FORMS': '0',
+ 'choices-MAX_NUM_FORMS': '2',
+ 'choices-0-choice': 'Zero',
+ 'choices-0-votes': '0',
+ 'choices-1-choice': 'One',
+ 'choices-1-votes': '1', # changed from initial
+ }
+ ChoiceFormSet = formset_factory(Choice, min_num=2, validate_min=True)
+ formset = ChoiceFormSet(data, auto_id=False, prefix='choices', initial=initial)
+ self.assertFalse(formset.forms[0].has_changed())
+ self.assertTrue(formset.forms[1].has_changed())
+ self.assertTrue(formset.is_valid())
+
def test_formset_validate_min_excludes_empty_forms(self):
data = {
'choices-TOTAL_FORMS': '2',