Ticket #13971: 13971_tests.diff

File 13971_tests.diff, 1.4 KB (added by matiasb, 4 years ago)

Tests added that shows the issue.

  • tests/regressiontests/model_forms_regress/tests.py

     
    442442        self.assertTrue(form.is_valid())
    443443        instance = construct_instance(form, Person(), fields=())
    444444        self.assertEqual(instance.name, '')
     445
     446
     447class BasePublicationForm(forms.ModelForm):
     448    date_published = forms.CharField()
     449    class Meta:
     450        model = Publication
     451
     452class PublicationFormWithFields(BasePublicationForm):
     453    class Meta(BasePublicationForm.Meta):
     454        fields = ('title',)
     455
     456class PublicationFormWithExclude(BasePublicationForm):
     457    class Meta(BasePublicationForm.Meta):
     458        exclude = ('date_published',)
     459       
     460class ExcludeCustomizedField(TestCase):
     461    """Test excluded form customized model field is not added to form (#13971)."""
     462   
     463    def test_field_is_not_added(self):
     464        form = PublicationFormWithFields()
     465        self.assert_('title' in form.fields)
     466        self.assert_('date_published' not in form.fields)
     467        self.assertEqual(len(form.fields), 1)
     468 
     469    def test_field_is_excluded(self):
     470        form = PublicationFormWithExclude()
     471        self.assert_('title' in form.fields)
     472        self.assert_('date_published' not in form.fields)
     473        self.assertEqual(len(form.fields), 1)
     474
Back to Top