51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from io import BytesIO
|
|
|
|
from PIL import Image
|
|
from django.core.files.base import ContentFile
|
|
from django.test import TestCase
|
|
|
|
from shop.models import ProductImage
|
|
from shop.tests.mixins import CreateProductsMixin
|
|
|
|
|
|
class TestProductImages(TestCase, CreateProductsMixin):
|
|
def setUp(self):
|
|
self.product = self.create_product()
|
|
|
|
def create_image_file(self, size=(768, 768)):
|
|
image = Image.new('RGB', size, '#ACACAC')
|
|
|
|
buffer = BytesIO()
|
|
image.save(fp=buffer, format='WEBP')
|
|
file = ContentFile(buffer.getvalue(), name=f'{self.product.slug}.webp')
|
|
return file
|
|
|
|
def test_product_image_creation(self):
|
|
file = self.create_image_file()
|
|
image = ProductImage.objects.create(product=self.product, original=file)
|
|
|
|
xl = Image.open(image.xl)
|
|
xl_dark = Image.open(image.xl_dark)
|
|
|
|
assert (1024, 1024) == xl.size == xl_dark.size
|
|
|
|
l = Image.open(image.l)
|
|
l_dark = Image.open(image.l_dark)
|
|
|
|
assert (512, 512) == l.size == l_dark.size
|
|
|
|
m = Image.open(image.m)
|
|
m_dark = Image.open(image.m_dark)
|
|
|
|
assert (256, 256) == m.size == m_dark.size
|
|
|
|
s = Image.open(image.s)
|
|
s_dark = Image.open(image.s_dark)
|
|
|
|
assert (128, 128) == s.size == s_dark.size
|
|
|
|
xs = Image.open(image.xs)
|
|
xs_dark = Image.open(image.xs_dark)
|
|
|
|
assert (96, 96) == xs.size == xs_dark.size
|