Enable env on GitHub Actions

This commit is contained in:
Joachim 2021-05-29 15:51:56 +02:00
parent ba39dad06c
commit cd7c0ccaea
4 changed files with 17 additions and 29 deletions

View file

@ -64,5 +64,6 @@ jobs:
EMAIL_HOST_USER: "" EMAIL_HOST_USER: ""
EMAIL_HOST_PASSWORD: "" EMAIL_HOST_PASSWORD: ""
EMAIL_USE_TLS: true EMAIL_USE_TLS: true
ENABLE_PREVIEW_IMAGES": true
run: | run: |
python manage.py test python manage.py test

View file

@ -15,9 +15,6 @@ from django.db.models import Avg
from bookwyrm import models, settings from bookwyrm import models, settings
from bookwyrm.tasks import app from bookwyrm.tasks import app
# remove after testing in Github Actions
import logging
IMG_WIDTH = settings.PREVIEW_IMG_WIDTH IMG_WIDTH = settings.PREVIEW_IMG_WIDTH
IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT
@ -308,12 +305,8 @@ def generate_preview_image(
def save_and_cleanup(image, instance=None): def save_and_cleanup(image, instance=None):
logging.warn("/start save_and_cleanup") if isinstance(instance, (models.Book, models.User, models.SiteSettings)):
if instance:
logging.warn("\nInstance OK, ")
file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4())) file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4()))
logging.warn("%s, " % file_name)
image_buffer = BytesIO() image_buffer = BytesIO()
try: try:
@ -322,10 +315,9 @@ def save_and_cleanup(image, instance=None):
except ValueError: except ValueError:
old_path = "" old_path = ""
logging.warn("path: %s, " % old_path)
# Save # Save
image.save(image_buffer, format="jpeg", quality=75) image.save(image_buffer, format="jpeg", quality=75)
instance.preview_image = InMemoryUploadedFile( instance.preview_image = InMemoryUploadedFile(
ContentFile(image_buffer.getvalue()), ContentFile(image_buffer.getvalue()),
"preview_image", "preview_image",
@ -334,26 +326,23 @@ def save_and_cleanup(image, instance=None):
image_buffer.tell(), image_buffer.tell(),
None, None,
) )
logging.warn("before save: %sx" % instance.preview_image.width)
logging.warn("%s, " % instance.preview_image.height)
save_without_broadcast = isinstance(instance, (models.Book, models.User)) save_without_broadcast = isinstance(instance, (models.Book, models.User))
if save_without_broadcast: if save_without_broadcast:
instance.save(broadcast=False) result = instance.save(broadcast=False)
else: else:
instance.save() instance.save()
instance.refresh_from_db()
logging.warn("after save: %sx" % instance.preview_image.width)
logging.warn("%s\n" % instance.preview_image.height)
# Clean up old file after saving # Clean up old file after saving
if os.path.exists(old_path): if os.path.exists(old_path):
os.remove(old_path) os.remove(old_path)
finally: finally:
image_buffer.close() image_buffer.close()
return True
else:
return False
logging.warn("end save_and_cleanup/\n")
@app.task @app.task
def generate_site_preview_image_task(): def generate_site_preview_image_task():

View file

@ -177,9 +177,6 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
NOSE_ARGS = ['--nocapture',
'--nologcapture',]
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/

View file

@ -1,5 +1,4 @@
""" test generating preview images """ """ test generating preview images """
import sys
import pathlib import pathlib
from unittest.mock import patch from unittest.mock import patch
from PIL import Image from PIL import Image
@ -22,7 +21,6 @@ from bookwyrm.preview_images import (
import logging import logging
@patch("bookwyrm.emailing.send_email.delay")
class PreviewImages(TestCase): class PreviewImages(TestCase):
"""every response to a get request, html or json""" """every response to a get request, html or json"""
@ -83,7 +81,6 @@ class PreviewImages(TestCase):
self.assertEqual(self.local_user.preview_image.width, 200) self.assertEqual(self.local_user.preview_image.width, 200)
self.assertEqual(self.local_user.preview_image.height, 200) self.assertEqual(self.local_user.preview_image.height, 200)
def test_site_preview(self, *args, **kwargs): def test_site_preview(self, *args, **kwargs):
"""generate site preview""" """generate site preview"""
generate_site_preview_image_task() generate_site_preview_image_task()
@ -114,5 +111,9 @@ class PreviewImages(TestCase):
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile) self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
self.assertIsNotNone(self.local_user.preview_image) self.assertIsNotNone(self.local_user.preview_image)
self.assertEqual(self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH) self.assertEqual(
self.assertEqual(self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT) self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH
)
self.assertEqual(
self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT
)