Skip to content

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

Add test for product image delete confirmation view

Jakub Draganek2d6ed0336144
diff --git a/tests/conftest.py b/tests/conftest.py
index 4e9fc476c7..d0114590d4 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,7 +3,8 @@ from __future__ import unicode_literals
from decimal import Decimal
import pytest
-from io import StringIO
+from io import BytesIO
+from PIL import Image
from django.contrib.auth.models import AnonymousUser
from django.utils.encoding import smart_text
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -167,7 +168,9 @@ def stock_location():
@pytest.fixture
def product_image():
- img_data = StringIO()
+ img_data = BytesIO()
+ image = Image.new('RGB', size=(1, 1))
+ image.save(img_data, format='JPEG')
return SimpleUploadedFile('product.jpg', img_data.getvalue())
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
index df0073e990..c25e33e9da 100644
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -259,6 +259,16 @@ def test_view_attribute_delete(admin_client, color_attribute):
assert not ProductAttribute.objects.filter(pk=color_attribute.pk)
+def test_view_product_image_not_deleted_before_confirmation(admin_client, product_with_image):
+ product_image = product_with_image.images.all()[0]
+ url = reverse('dashboard:product-image-delete',
+ kwargs={'img_pk': product_image.pk,
+ 'product_pk': product_with_image.pk})
+ response = admin_client.get(url)
+ assert response.status_code == HTTP_STATUS_OK
+ assert ProductImage.objects.filter(pk=product_image.pk).count()
+
+
def test_view_product_image_delete(admin_client, product_with_image):
product_image = product_with_image.images.all()[0]
url = reverse('dashboard:product-image-delete',