Code

Ticket #13971: 13971_tests.diff

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

Tests added that shows the issue.

Line 
1Index: tests/regressiontests/model_forms_regress/tests.py
2===================================================================
3--- tests/regressiontests/model_forms_regress/tests.py  (revision 14551)
4+++ tests/regressiontests/model_forms_regress/tests.py  (working copy)
5@@ -442,3 +442,33 @@
6         self.assertTrue(form.is_valid())
7         instance = construct_instance(form, Person(), fields=())
8         self.assertEqual(instance.name, '')
9+
10+
11+class BasePublicationForm(forms.ModelForm):
12+    date_published = forms.CharField()
13+    class Meta:
14+        model = Publication
15+
16+class PublicationFormWithFields(BasePublicationForm):
17+    class Meta(BasePublicationForm.Meta):
18+        fields = ('title',)
19+
20+class PublicationFormWithExclude(BasePublicationForm):
21+    class Meta(BasePublicationForm.Meta):
22+        exclude = ('date_published',)
23+       
24+class ExcludeCustomizedField(TestCase):
25+    """Test excluded form customized model field is not added to form (#13971)."""
26+   
27+    def test_field_is_not_added(self):
28+        form = PublicationFormWithFields()
29+        self.assert_('title' in form.fields)
30+        self.assert_('date_published' not in form.fields)
31+        self.assertEqual(len(form.fields), 1)
32+
33+    def test_field_is_excluded(self):
34+        form = PublicationFormWithExclude()
35+        self.assert_('title' in form.fields)
36+        self.assert_('date_published' not in form.fields)
37+        self.assertEqual(len(form.fields), 1)
38+