From 872084d61a784813147b67339c305c203c8d8e62 Mon Sep 17 00:00:00 2001 From: Joachim Date: Fri, 28 May 2021 23:41:41 +0200 Subject: [PATCH] Update test_preview_images.py --- bookwyrm/tests/test_preview_images.py | 59 ++++++++++++--------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/bookwyrm/tests/test_preview_images.py b/bookwyrm/tests/test_preview_images.py index 600a4569..86ed0028 100644 --- a/bookwyrm/tests/test_preview_images.py +++ b/bookwyrm/tests/test_preview_images.py @@ -3,7 +3,6 @@ import sys import pathlib from unittest.mock import patch from PIL import Image -import re from django.test import TestCase from django.test.client import RequestFactory @@ -76,44 +75,36 @@ class PreviewImages(TestCase): generate_site_preview_image_task() updated_site = models.SiteSettings.objects.get() - # site_preview_image = updated_site.preview_image + site_preview_image = updated_site.preview_image - output = models.fields.image_serializer(updated_site.preview_image, alt="alt text") - self.assertIsNotNone( - re.match( - r".*\.png", - output.url, - ) + self.assertIsInstance(site_preview_image, ImageFieldFile) + result = Image.open(site_preview_image) + self.assertEqual( + result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) ) - # self.assertIsInstance(site_preview_image, ImageFieldFile) - # result = Image.open(site_preview_image) - # self.assertEqual( - # result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) - # ) + def test_edition_preview(self, *args, **kwargs): + """generate user preview""" + generate_edition_preview_image_task(self.book.id) - # def test_edition_preview(self, *args, **kwargs): - # """generate user preview""" - # generate_edition_preview_image_task(self.book.id) + updated_book = models.Book.objects.get(id=self.book.id) + book_preview_image = updated_book.preview_image - # updated_book = models.Book.objects.get(id=self.book.id) - # book_preview_image = updated_book.preview_image + self.assertIsInstance(book_preview_image, ImageFieldFile) + result = Image.open(book_preview_image) + self.assertEqual( + result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) + ) - # self.assertIsInstance(book_preview_image, ImageFieldFile) - # result = Image.open(book_preview_image) - # self.assertEqual( - # result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) - # ) + def test_user_preview(self, *args, **kwargs): + """generate user preview""" + generate_user_preview_image_task(self.local_user.id) - # def test_user_preview(self, *args, **kwargs): - # """generate user preview""" - # generate_user_preview_image_task(self.local_user.id) + updated_user = models.User.objects.get(id=self.local_user.id) + user_preview_image = updated_user.preview_image - # updated_user = models.User.objects.get(id=self.local_user.id) - # user_preview_image = updated_user.preview_image - - # self.assertIsInstance(user_preview_image, ImageFieldFile) - # result = Image.open(user_preview_image) - # self.assertEqual( - # result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) - # ) + self.assertIsInstance(user_preview_image, ImageFieldFile) + result = Image.open(user_preview_image) + self.assertEqual( + result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) + )