Ticket #9061: before.patch

File before.patch, 1.6 KB (added by Daniel Ward, 4 years ago)

Latest 'before' test to confirm behaviour

  • tests/forms_tests/tests/test_formsets.py

    diff --git tests/forms_tests/tests/test_formsets.py tests/forms_tests/tests/test_formsets.py
    index 0bd2811..b96c75e 100644
    class FormsFormsetTestCase(SimpleTestCase): 
    461461        self.assertTrue(p.is_valid())
    462462        self.assertEqual(len(p.deleted_forms), 1)
    463463
     464    def test_delete_fields_are_added_for_extra_formset_forms(self):
     465
     466        """
     467        When a formset is built with can_delete=True and extra>=1, the extra
     468        forms should be seen to hold DELETE fields.
     469        """
     470
     471        class GenericForm(Form):
     472            foo = CharField()
     473
     474        GenericFormFormset = formset_factory(
     475            form=GenericForm,
     476            can_delete=True,
     477            extra=2)
     478
     479        # Instantiate formset and check DELETE fields exist
     480
     481        formset = GenericFormFormset()
     482
     483        self.assertEqual(len(formset), 2)
     484
     485        self.assertIn('DELETE', formset.forms[0].fields)
     486        self.assertIn('DELETE', formset.forms[1].fields)
     487
     488        # Instantiate formset with existing data and check DELETE fields exist
     489
     490        formset = GenericFormFormset(initial=[{'foo': 'bar'}])
     491
     492        self.assertEqual(len(formset), 3)
     493
     494        self.assertIn('DELETE', formset.forms[0].fields)
     495        self.assertIn('DELETE', formset.forms[1].fields)
     496        self.assertIn('DELETE', formset.forms[2].fields)
     497
    464498    def test_formsets_with_ordering(self):
    465499        # FormSets with ordering ######################################################
    466500        # We can also add ordering ability to a FormSet with an argument to
Back to Top