Exemple #1
0
    def test_contact_formset(self):
        sponsor = baker.make(Sponsor)
        self.data.update({
            "contact-0-name": "Bernardo",
            "contact-0-email": "*****@*****.**",
            "contact-0-phone": "+1999999999",
            "contact-1-name": "Foo",
            "contact-1-email": "*****@*****.**",
            "contact-1-phone": "+1111111111",
            "contact-TOTAL_FORMS": 2,
        })

        formset = SponsorContactFormSet(self.data, prefix="contact")
        self.assertTrue(formset.is_valid())
        for form in formset.forms:
            contact = form.save(commit=False)
            contact.sponsor = sponsor
            contact.save()

        self.assertEqual(2, SponsorContact.objects.count())
 def test_invalidate_formset_if_no_form(self):
     self.data["contact-TOTAL_FORMS"] = 0
     formset = SponsorContactFormSet(self.data, prefix="contact")
     self.assertFalse(formset.is_valid())