Merge pull request #2192 from bookwyrm-social/tests

Tests for image generator file
This commit is contained in:
Mouse Reeve 2022-07-07 11:47:18 -07:00 committed by GitHub
commit 8e18c21460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -55,5 +55,6 @@ jobs:
EMAIL_HOST_PASSWORD: ""
EMAIL_USE_TLS: true
ENABLE_PREVIEW_IMAGES: false
ENABLE_THUMBNAIL_GENERATION: true
run: |
pytest -n 3

View file

@ -1,6 +1,10 @@
""" testing models """
from dateutil.parser import parse
from io import BytesIO
import pathlib
from dateutil.parser import parse
from PIL import Image
from django.core.files.base import ContentFile
from django.test import TestCase
from django.utils import timezone
@ -96,3 +100,28 @@ class Book(TestCase):
self.first_edition.description = "hi"
self.first_edition.save()
self.assertEqual(self.first_edition.edition_rank, 1)
def test_thumbnail_fields(self):
"""Just hit them"""
image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg"
)
image = Image.open(image_file)
output = BytesIO()
image.save(output, format=image.format)
book = models.Edition.objects.create(title="hello")
book.cover.save("test.jpg", ContentFile(output.getvalue()))
self.assertIsNotNone(book.cover_bw_book_xsmall_webp.url)
self.assertIsNotNone(book.cover_bw_book_xsmall_jpg.url)
self.assertIsNotNone(book.cover_bw_book_small_webp.url)
self.assertIsNotNone(book.cover_bw_book_small_jpg.url)
self.assertIsNotNone(book.cover_bw_book_medium_webp.url)
self.assertIsNotNone(book.cover_bw_book_medium_jpg.url)
self.assertIsNotNone(book.cover_bw_book_large_webp.url)
self.assertIsNotNone(book.cover_bw_book_large_jpg.url)
self.assertIsNotNone(book.cover_bw_book_xlarge_webp.url)
self.assertIsNotNone(book.cover_bw_book_xlarge_jpg.url)
self.assertIsNotNone(book.cover_bw_book_xxlarge_webp.url)
self.assertIsNotNone(book.cover_bw_book_xxlarge_jpg.url)