| 881 | | class TestEmptyFormSet(TestCase): |
| | 881 | def test_empty_forms_are_unbound(self): |
| | 882 | data = { |
| | 883 | 'form-TOTAL_FORMS': u'1', |
| | 884 | 'form-INITIAL_FORMS': u'0', |
| | 885 | 'form-0-title': u'Test', |
| | 886 | 'form-0-pub_date': u'1904-06-16', |
| | 887 | } |
| | 888 | unbound_formset = ArticleFormSet() |
| | 889 | bound_formset = ArticleFormSet(data) |
| | 890 | |
| | 891 | empty_forms = [] |
| | 892 | |
| | 893 | empty_forms.append(unbound_formset.empty_form) |
| | 894 | empty_forms.append(bound_formset.empty_form) |
| | 895 | |
| | 896 | # Empty forms should be unbound |
| | 897 | self.assertFalse(empty_forms[0].is_bound) |
| | 898 | self.assertFalse(empty_forms[1].is_bound) |
| | 899 | |
| | 900 | # The empty forms should be equal. |
| | 901 | self.assertEqual(empty_forms[0].as_p(), empty_forms[1].as_p()) |
| | 902 | |
| | 903 | class TestEmptyFormSet(TestCase): |
| 883 | | def test_empty_formset_is_valid(self): |
| 884 | | EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate) |
| 885 | | formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form") |
| 886 | | formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form") |
| 887 | | self.assertFalse(formset.is_valid()) |
| 888 | | self.assertFalse(formset2.is_valid()) |
| | 905 | def test_empty_formset_is_valid(self): |
| | 906 | EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate) |
| | 907 | formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form") |
| | 908 | formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form") |
| | 909 | self.assertFalse(formset.is_valid()) |
| | 910 | self.assertFalse(formset2.is_valid()) |