Ticket #8160: 8160_test.diff

File 8160_test.diff, 1.3 KB (added by Claude Paroz, 13 years ago)

Test showing working functionality

  • tests/modeltests/model_formsets/tests.py

    diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py
    index 34f8d47..ee58702 100644
    a b class ModelFormsetTest(TestCase):  
    353353        self.assertEqual(poet1.name, 'Vladimir Mayakovsky')
    354354        self.assertEqual(poet2.name, 'Vladimir Mayakovsky')
    355355
     356    def test_custom_form(self):
     357        """ Test that model_formset respects fields and exclude parameters of
     358            custom form
     359        """
     360        class PostForm1(forms.ModelForm):
     361            class Meta:
     362                model = Post
     363                fields = ('title', 'posted')
     364
     365        class PostForm2(forms.ModelForm):
     366            class Meta:
     367                model = Post
     368                exclude = ('subtitle',)
     369
     370        PostFormSet = modelformset_factory(Post, form=PostForm1)
     371        formset = PostFormSet()
     372        self.assertFalse("subtitle" in formset.forms[0].fields)
     373
     374        PostFormSet = modelformset_factory(Post, form=PostForm2)
     375        formset = PostFormSet()
     376        self.assertFalse("subtitle" in formset.forms[0].fields)
     377
    356378    def test_model_inheritance(self):
    357379        BetterAuthorFormSet = modelformset_factory(BetterAuthor)
    358380        formset = BetterAuthorFormSet()
Back to Top