Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix thumbnail generation (#12347)

Przemysław Ładab7952addef53
diff --git a/saleor/thumbnail/tests/test_utils.py b/saleor/thumbnail/tests/test_utils.py
index 82a8869940..698afbb06a 100644
--- a/saleor/thumbnail/tests/test_utils.py
+++ b/saleor/thumbnail/tests/test_utils.py
@@ -4,8 +4,10 @@ import graphene
import pytest
from django.core.files import File
+from .. import ThumbnailFormat
from ..models import Thumbnail
from ..utils import (
+ ProcessedImage,
get_image_or_proxy_url,
get_thumbnail_size,
prepare_image_proxy_url,
@@ -93,3 +95,20 @@ def test_get_image_or_proxy_url_thumbnail_url_returned(collection, media_root):
# then
assert url == thumbnail.image.url
+
+
[email protected]("thumb_format", [ThumbnailFormat.WEBP, ThumbnailFormat.AVIF])
+def test_processed_image_preprocess_method_called(category_with_image, thumb_format):
+ # given
+ image_path = category_with_image.background_image.name
+ processed_image = ProcessedImage(image_path, 128, thumb_format)
+ preprocess_method_name = f"preprocess_{thumb_format.upper()}"
+ preprocess_mock = MagicMock()
+ preprocess_mock.side_effect = getattr(processed_image, preprocess_method_name)
+ setattr(processed_image, preprocess_method_name, preprocess_mock)
+
+ # when
+ processed_image.create_thumbnail()
+
+ # then
+ preprocess_mock.assert_called_once()
diff --git a/saleor/thumbnail/utils.py b/saleor/thumbnail/utils.py
index e0a42a90f5..4a3604b843 100644
--- a/saleor/thumbnail/utils.py
+++ b/saleor/thumbnail/utils.py
@@ -101,7 +101,7 @@ class ProcessedImage:
):
self.image_path = image_path
self.size = size
- self.format = format
+ self.format = format.upper() if format else None
self.storage = storage
def create_thumbnail(self):