mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-18 14:16:45 +00:00
Try another way
This commit is contained in:
parent
022182e114
commit
cc0881b11c
2 changed files with 39 additions and 42 deletions
|
@ -309,7 +309,7 @@ def save_and_cleanup(image, instance=None):
|
|||
file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4()))
|
||||
image_buffer = BytesIO()
|
||||
|
||||
# try:
|
||||
try:
|
||||
try:
|
||||
old_path = instance.preview_image.path
|
||||
except ValueError:
|
||||
|
@ -335,7 +335,7 @@ def save_and_cleanup(image, instance=None):
|
|||
# Clean up old file after saving
|
||||
if os.path.exists(old_path):
|
||||
os.remove(old_path)
|
||||
# finally:
|
||||
finally:
|
||||
image_buffer.close()
|
||||
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class PreviewImages(TestCase):
|
|||
)
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
self.edition = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
|
@ -77,22 +77,20 @@ class PreviewImages(TestCase):
|
|||
self.site.refresh_from_db()
|
||||
|
||||
self.assertIsInstance(self.site.preview_image, ImageFieldFile)
|
||||
result = Image.open(self.site.preview_image)
|
||||
self.assertEqual(
|
||||
result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT)
|
||||
)
|
||||
self.assertIsNotNone(self.site.preview_image)
|
||||
self.assertEqual(self.site.preview_image.width, settings.PREVIEW_IMG_WIDTH)
|
||||
self.assertEqual(self.site.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||
|
||||
def test_edition_preview(self, *args, **kwargs):
|
||||
"""generate user preview"""
|
||||
generate_edition_preview_image_task(self.book.id)
|
||||
"""generate edition preview"""
|
||||
generate_edition_preview_image_task(self.edition.id)
|
||||
|
||||
self.book.refresh_from_db()
|
||||
self.edition.refresh_from_db()
|
||||
|
||||
self.assertIsInstance(self.book.preview_image, ImageFieldFile)
|
||||
result = Image.open(self.book.preview_image)
|
||||
self.assertEqual(
|
||||
result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT)
|
||||
)
|
||||
self.assertIsInstance(self.edition.preview_image, ImageFieldFile)
|
||||
self.assertIsNotNone(self.edition.preview_image)
|
||||
self.assertEqual(self.edition.preview_image.width, settings.PREVIEW_IMG_WIDTH)
|
||||
self.assertEqual(self.edition.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||
|
||||
def test_user_preview(self, *args, **kwargs):
|
||||
"""generate user preview"""
|
||||
|
@ -101,7 +99,6 @@ class PreviewImages(TestCase):
|
|||
self.local_user.refresh_from_db()
|
||||
|
||||
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
|
||||
result = Image.open(self.local_user.preview_image)
|
||||
self.assertEqual(
|
||||
result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT)
|
||||
)
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue