mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-26 18:10:36 +00:00
Enable env on GitHub Actions
This commit is contained in:
parent
ba39dad06c
commit
cd7c0ccaea
4 changed files with 17 additions and 29 deletions
1
.github/workflows/django-tests.yml
vendored
1
.github/workflows/django-tests.yml
vendored
|
@ -64,5 +64,6 @@ jobs:
|
|||
EMAIL_HOST_USER: ""
|
||||
EMAIL_HOST_PASSWORD: ""
|
||||
EMAIL_USE_TLS: true
|
||||
ENABLE_PREVIEW_IMAGES": true
|
||||
run: |
|
||||
python manage.py test
|
||||
|
|
|
@ -15,9 +15,6 @@ from django.db.models import Avg
|
|||
from bookwyrm import models, settings
|
||||
from bookwyrm.tasks import app
|
||||
|
||||
# remove after testing in Github Actions
|
||||
import logging
|
||||
|
||||
|
||||
IMG_WIDTH = settings.PREVIEW_IMG_WIDTH
|
||||
IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT
|
||||
|
@ -308,12 +305,8 @@ def generate_preview_image(
|
|||
|
||||
|
||||
def save_and_cleanup(image, instance=None):
|
||||
logging.warn("/start save_and_cleanup")
|
||||
|
||||
if instance:
|
||||
logging.warn("\nInstance OK, ")
|
||||
if isinstance(instance, (models.Book, models.User, models.SiteSettings)):
|
||||
file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4()))
|
||||
logging.warn("%s, " % file_name)
|
||||
image_buffer = BytesIO()
|
||||
|
||||
try:
|
||||
|
@ -321,11 +314,10 @@ def save_and_cleanup(image, instance=None):
|
|||
old_path = instance.preview_image.path
|
||||
except ValueError:
|
||||
old_path = ""
|
||||
|
||||
logging.warn("path: %s, " % old_path)
|
||||
|
||||
# Save
|
||||
image.save(image_buffer, format="jpeg", quality=75)
|
||||
|
||||
instance.preview_image = InMemoryUploadedFile(
|
||||
ContentFile(image_buffer.getvalue()),
|
||||
"preview_image",
|
||||
|
@ -334,26 +326,23 @@ def save_and_cleanup(image, instance=None):
|
|||
image_buffer.tell(),
|
||||
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))
|
||||
if save_without_broadcast:
|
||||
instance.save(broadcast=False)
|
||||
result = instance.save(broadcast=False)
|
||||
else:
|
||||
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
|
||||
if os.path.exists(old_path):
|
||||
os.remove(old_path)
|
||||
|
||||
finally:
|
||||
image_buffer.close()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
logging.warn("end save_and_cleanup/\n")
|
||||
|
||||
@app.task
|
||||
def generate_site_preview_image_task():
|
||||
|
|
|
@ -177,9 +177,6 @@ USE_L10N = True
|
|||
USE_TZ = True
|
||||
|
||||
|
||||
NOSE_ARGS = ['--nocapture',
|
||||
'--nologcapture',]
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
""" test generating preview images """
|
||||
import sys
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
from PIL import Image
|
||||
|
@ -22,7 +21,6 @@ from bookwyrm.preview_images import (
|
|||
import logging
|
||||
|
||||
|
||||
@patch("bookwyrm.emailing.send_email.delay")
|
||||
class PreviewImages(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
|
@ -83,9 +81,8 @@ class PreviewImages(TestCase):
|
|||
self.assertEqual(self.local_user.preview_image.width, 200)
|
||||
self.assertEqual(self.local_user.preview_image.height, 200)
|
||||
|
||||
|
||||
def test_site_preview(self, *args, **kwargs):
|
||||
"""generate site preview"""
|
||||
"""generate site preview"""
|
||||
generate_site_preview_image_task()
|
||||
|
||||
self.site.refresh_from_db()
|
||||
|
@ -96,7 +93,7 @@ class PreviewImages(TestCase):
|
|||
self.assertEqual(self.site.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||
|
||||
def test_edition_preview(self, *args, **kwargs):
|
||||
"""generate edition preview"""
|
||||
"""generate edition preview"""
|
||||
generate_edition_preview_image_task(self.edition.id)
|
||||
|
||||
self.edition.refresh_from_db()
|
||||
|
@ -107,12 +104,16 @@ class PreviewImages(TestCase):
|
|||
self.assertEqual(self.edition.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||
|
||||
def test_user_preview(self, *args, **kwargs):
|
||||
"""generate user preview"""
|
||||
"""generate user preview"""
|
||||
generate_user_preview_image_task(self.local_user.id)
|
||||
|
||||
self.local_user.refresh_from_db()
|
||||
|
||||
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
|
||||
self.assertIsNotNone(self.local_user.preview_image)
|
||||
self.assertEqual(self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH)
|
||||
self.assertEqual(self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||
self.assertEqual(
|
||||
self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH
|
||||
)
|
||||
self.assertEqual(
|
||||
self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue