diff --git a/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py b/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py index 581dc2994e..a2dd97db00 100644 --- a/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py +++ b/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py @@ -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 diff --git a/wagtail/tests/modeladmintest/migrations/0005_book_cover_image.py b/wagtail/tests/modeladmintest/migrations/0005_book_cover_image.py new file mode 100644 index 0000000000..ae789806c0 --- /dev/null +++ b/wagtail/tests/modeladmintest/migrations/0005_book_cover_image.py @@ -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'), + ), + ] diff --git a/wagtail/tests/modeladmintest/models.py b/wagtail/tests/modeladmintest/models.py index ae8d216b42..b47b587489 100644 --- a/wagtail/tests/modeladmintest/models.py +++ b/wagtail/tests/modeladmintest/models.py @@ -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 diff --git a/wagtail/tests/modeladmintest/wagtail_hooks.py b/wagtail/tests/modeladmintest/wagtail_hooks.py index c5606e5ed6..384d6c0004 100644 --- a/wagtail/tests/modeladmintest/wagtail_hooks.py +++ b/wagtail/tests/modeladmintest/wagtail_hooks.py @@ -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 { diff --git a/wagtail/wagtailadmin/tests/api/test_images.py b/wagtail/wagtailadmin/tests/api/test_images.py index 9fc37fe462..1ca27838b7 100644 --- a/wagtail/wagtailadmin/tests/api/test_images.py +++ b/wagtail/wagtailadmin/tests/api/test_images.py @@ -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'])