summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-04-28 09:32:40 -0400
committerGitHub <noreply@github.com>2017-04-28 09:32:40 -0400
commitf04a40491764bdc9a2ebbfc03fa7be424fb3ce63 (patch)
tree90939e992037286524a373db11dd43d19888633c /tests/forms_tests
parenteb4724a0632928bda2a512a9117a91260096e457 (diff)
Fixed #28130 -- Fixed formset min_num validation with initial, unchanged forms.
Regression in f5c6295797b8332134fd89e0209a18a1d1d45e0c.
Diffstat (limited to 'tests/forms_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 f552f689dc..c1dc8e8560 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -402,6 +402,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',