mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Add some missing test coverage to modeladmin
Added an image to the Book model (affecting the index and inspect views), and renamed TestInspectView tests to test_*
This commit is contained in:
parent
1b6575fbfa
commit
a002bb8c39
@ -6,6 +6,8 @@ from django.test import TestCase
|
||||
|
||||
from wagtail.tests.modeladmintest.models import Author, Book, Publisher
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
from wagtail.wagtailimages.models import Image
|
||||
from wagtail.wagtailimages.tests.utils import get_test_image_file
|
||||
|
||||
|
||||
class TestIndexView(TestCase, WagtailTestUtils):
|
||||
@ -14,6 +16,14 @@ class TestIndexView(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
|
||||
img = Image.objects.create(
|
||||
title="LOTR cover",
|
||||
file=get_test_image_file(),
|
||||
)
|
||||
book = Book.objects.get(title="The Lord of the Rings")
|
||||
book.cover_image = img
|
||||
book.save()
|
||||
|
||||
def get(self, **params):
|
||||
return self.client.get('/admin/modeladmintest/book/', params)
|
||||
|
||||
@ -152,17 +162,25 @@ class TestInspectView(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
|
||||
img = Image.objects.create(
|
||||
title="LOTR cover",
|
||||
file=get_test_image_file(),
|
||||
)
|
||||
book = Book.objects.get(title="The Lord of the Rings")
|
||||
book.cover_image = img
|
||||
book.save()
|
||||
|
||||
def get_for_author(self, author_id):
|
||||
return self.client.get('/admin/modeladmintest/author/inspect/%d/' % author_id)
|
||||
|
||||
def get_for_book(self, book_id):
|
||||
return self.client.get('/admin/modeladmintest/book/inspect/%d/' % book_id)
|
||||
|
||||
def author_test_simple(self):
|
||||
def test_author_simple(self):
|
||||
response = self.get_for_author(1)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def author_test_name_present(self):
|
||||
def test_author_name_present(self):
|
||||
"""
|
||||
The author name should appear twice. Once in the header, and once
|
||||
more in the field listing
|
||||
@ -170,19 +188,19 @@ class TestInspectView(TestCase, WagtailTestUtils):
|
||||
response = self.get_for_author(1)
|
||||
self.assertContains(response, 'J. R. R. Tolkien', 2)
|
||||
|
||||
def author_test_dob_not_present(self):
|
||||
def test_author_dob_not_present(self):
|
||||
"""
|
||||
The date of birth shouldn't appear, because the field wasn't included
|
||||
in the `inspect_view_fields` list
|
||||
"""
|
||||
response = self.get_for_author(1)
|
||||
self.assertNotContains(response, '1892', 2)
|
||||
self.assertNotContains(response, '1892')
|
||||
|
||||
def book_test_simple(self):
|
||||
def test_book_simple(self):
|
||||
response = self.get_for_book(1)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def book_test_title_present(self):
|
||||
def test_book_title_present(self):
|
||||
"""
|
||||
The book title should appear once only, in the header, as 'title'
|
||||
was added to the `inspect_view_fields_ignore` list
|
||||
@ -190,7 +208,7 @@ class TestInspectView(TestCase, WagtailTestUtils):
|
||||
response = self.get_for_book(1)
|
||||
self.assertContains(response, 'The Lord of the Rings', 1)
|
||||
|
||||
def book_test_author_present(self):
|
||||
def test_book_author_present(self):
|
||||
"""
|
||||
The author name should appear, because 'author' is not in
|
||||
`inspect_view_fields_ignore` and should be returned by the
|
||||
|
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.11 on 2016-11-14 20:12
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailimages', '0016_deprecate_rendition_filter_relation'),
|
||||
('modeladmintest', '0004_venuepage'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='cover_image',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='wagtailimages.Image'),
|
||||
),
|
||||
]
|
@ -20,6 +20,7 @@ class Author(models.Model):
|
||||
class Book(models.Model, index.Indexed):
|
||||
author = models.ForeignKey(Author, on_delete=models.PROTECT)
|
||||
title = models.CharField(max_length=255)
|
||||
cover_image = models.ForeignKey('wagtailimages.Image', on_delete=models.SET_NULL, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup, modeladmin_register
|
||||
from wagtail.contrib.modeladmin.options import (
|
||||
ModelAdmin, ModelAdminGroup, ThumbnailMixin, modeladmin_register)
|
||||
from wagtail.contrib.modeladmin.views import CreateView
|
||||
from wagtail.tests.testapp.models import BusinessChild, EventPage, SingleEventPage
|
||||
|
||||
@ -18,15 +19,16 @@ class AuthorModelAdmin(ModelAdmin):
|
||||
inspect_view_fields = ('name', )
|
||||
|
||||
|
||||
class BookModelAdmin(ModelAdmin):
|
||||
class BookModelAdmin(ThumbnailMixin, ModelAdmin):
|
||||
model = Book
|
||||
menu_order = 300
|
||||
list_display = ('title', 'author')
|
||||
list_display = ('title', 'author', 'admin_thumb')
|
||||
list_filter = ('author', )
|
||||
ordering = ('title', )
|
||||
search_fields = ('title', )
|
||||
inspect_view_enabled = True
|
||||
inspect_view_fields_exclude = ('title', )
|
||||
thumb_image_field_name = 'cover_image'
|
||||
|
||||
def get_extra_attrs_for_row(self, obj, context):
|
||||
return {
|
||||
|
@ -194,11 +194,9 @@ class TestAdminImageDetail(AdminAPITestCase, TestImageDetail):
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertIn('thumbnail', content)
|
||||
self.assertEqual(content['thumbnail'], {
|
||||
'url': '/media/images/test.max-165x165.png',
|
||||
'width': 165,
|
||||
'height': 123
|
||||
})
|
||||
self.assertEqual(content['thumbnail']['width'], 165)
|
||||
self.assertEqual(content['thumbnail']['height'], 123)
|
||||
self.assertTrue(content['thumbnail']['url'].startswith('/media/images/test'))
|
||||
|
||||
# Check that source_image_error didn't appear
|
||||
self.assertNotIn('source_image_error', content['meta'])
|
||||
|
Loading…
Reference in New Issue
Block a user