Added a test for checking the short description and processed reviewer's feedback

This commit is contained in:
Wesley van Lee 2019-03-14 17:55:14 +01:00
parent 935028a57e
commit e389a78e54
5 changed files with 17 additions and 8 deletions

View file

@ -103,7 +103,7 @@ class TestCreateView(TestCase, WagtailTestUtils):
class TestInspectView(TestCase, WagtailTestUtils):
fixtures = ['test_specific.json']
fixtures = ['test_specific.json', 'modeladmintest_test.json']
def setUp(self):
self.login()
@ -157,6 +157,10 @@ class TestInspectView(TestCase, WagtailTestUtils):
response = self.get(100)
self.assertEqual(response.status_code, 404)
def test_label_display(self):
response = self.client.get('/admin/modeladmintest/author/inspect/1/')
self.assertContains(response, 'Birth information')
class TestEditView(TestCase, WagtailTestUtils):
fixtures = ['test_specific.json']

View file

@ -222,11 +222,11 @@ class TestInspectView(TestCase, WagtailTestUtils):
def test_author_name_present(self):
"""
The author name should appear twice. Once in the header, and once
more in the field listing
The author name should appear three times. Once in the header, once
in the name field and once more in the birth string
"""
response = self.get_for_author(1)
self.assertContains(response, 'J. R. R. Tolkien', 2)
self.assertContains(response, 'J. R. R. Tolkien', 3)
def test_author_dob_not_present(self):
"""

View file

@ -842,9 +842,9 @@ class InspectView(InstanceSpecificView):
def get_meta_title(self):
return _('Inspecting %s') % self.verbose_name
def get_field_label(self, field_name):
def get_field_label(self, field_name, field=None):
""" Return a label to display for a field """
return label_for_field(field_name, model=self.model, model_admin=self.model_admin)
return label_for_field(field_name, model=self.model)
def get_field_display_value(self, field_name, field=None):
""" Return a display value for a field/attribute """
@ -924,7 +924,7 @@ class InspectView(InstanceSpecificView):
except FieldDoesNotExist:
field = None
return {
'label': self.get_field_label(field_name),
'label': self.get_field_label(field_name, field),
'value': self.get_field_display_value(field_name, field),
}

View file

@ -9,6 +9,11 @@ class Author(models.Model):
name = models.CharField(max_length=255)
date_of_birth = models.DateField()
def author_birth_string(self):
return '{} was born in pallet town'.format(self.name)
author_birth_string.short_description = "Birth information"
def __str__(self):
return self.name

View file

@ -15,7 +15,7 @@ class AuthorModelAdmin(ModelAdmin):
list_filter = ('date_of_birth', )
search_fields = ('name', )
inspect_view_enabled = True
inspect_view_fields = ('name', )
inspect_view_fields = ('name', 'author_birth_string')
def last_book(self, obj):
# For testing use of modeladmin methods in list_display