summaryrefslogtreecommitdiff
path: root/tests/admin_utils
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-08-18 16:15:18 -0400
committerTim Graham <timograham@gmail.com>2018-08-20 11:14:20 -0400
commitd311124be59df64278f3149d68e79ce45b8a6c64 (patch)
tree1c47886fa1d9d210723957f12ea541003e2f2a30 /tests/admin_utils
parent0e7a9525baec11d75badc37f8d8b92f17dba60ae (diff)
Fixed #29682 -- Fixed admin change form crash if a view-only model's form has an extra field.
Diffstat (limited to 'tests/admin_utils')
-rw-r--r--tests/admin_utils/tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py
index d2697ca87e..463ba9556d 100644
--- a/tests/admin_utils/tests.py
+++ b/tests/admin_utils/tests.py
@@ -286,6 +286,22 @@ class UtilsTests(SimpleTestCase):
("not Really the Model", MockModelAdmin.test_from_model)
)
+ def test_label_for_field_form_argument(self):
+ class ArticleForm(forms.ModelForm):
+ extra_form_field = forms.BooleanField()
+
+ class Meta:
+ fields = '__all__'
+ model = Article
+
+ self.assertEqual(
+ label_for_field('extra_form_field', Article, form=ArticleForm()),
+ 'Extra form field'
+ )
+ msg = "Unable to lookup 'nonexistent' on Article or ArticleForm"
+ with self.assertRaisesMessage(AttributeError, msg):
+ label_for_field('nonexistent', Article, form=ArticleForm()),
+
def test_label_for_property(self):
# NOTE: cannot use @property decorator, because of
# AttributeError: 'property' object has no attribute 'short_description'