|
1 | 1 | import io
|
2 | 2 | import os
|
3 | 3 | import time
|
| 4 | +from copy import deepcopy |
4 | 5 |
|
| 6 | +import pkg_resources |
5 | 7 | import pytest
|
6 | 8 | from django.conf import settings
|
7 | 9 | from django.core.files.storage import default_storage
|
8 | 10 | from django.core.files.uploadedfile import SimpleUploadedFile
|
| 11 | +from django.db.models.fields.files import ImageFieldFile |
| 12 | +from django.utils import version |
9 | 13 | from PIL import Image
|
10 | 14 |
|
| 15 | +from stdimage.models import StdImageFieldFile |
| 16 | + |
11 | 17 | from . import models
|
12 | 18 | from .models import (
|
13 | 19 | AdminDeleteModel,
|
@@ -170,6 +176,47 @@ def test_defer(self, db, django_assert_num_queries):
|
170 | 176 | deferred.image
|
171 | 177 | assert instance.image.thumbnail == deferred.image.thumbnail
|
172 | 178 |
|
| 179 | + @pytest.mark.django_db |
| 180 | + def test_variations_deepcopy(self): |
| 181 | + """Tests test_variations() with a deep copied object""" |
| 182 | + instance_original = ResizeModel.objects.create( |
| 183 | + image=self.fixtures["600x400.jpg"] |
| 184 | + ) |
| 185 | + instance = deepcopy(instance_original) |
| 186 | + assert isinstance(instance.image, StdImageFieldFile) |
| 187 | + |
| 188 | + assert hasattr(instance.image, "thumbnail") |
| 189 | + assert hasattr(instance.image, "medium") |
| 190 | + |
| 191 | + assert isinstance(instance.image.thumbnail, ImageFieldFile) |
| 192 | + assert isinstance(instance.image.medium, ImageFieldFile) |
| 193 | + |
| 194 | + source_file = self.fixtures["600x400.jpg"] |
| 195 | + |
| 196 | + assert os.path.exists(os.path.join(IMG_DIR, "600x400.jpg")) |
| 197 | + assert instance.image.width == 600 |
| 198 | + assert instance.image.height == 400 |
| 199 | + path = os.path.join(IMG_DIR, "600x400.jpg") |
| 200 | + |
| 201 | + with open(path, "rb") as f: |
| 202 | + source_file.seek(0) |
| 203 | + assert source_file.read() == f.read() |
| 204 | + |
| 205 | + path = os.path.join(IMG_DIR, "600x400.medium.jpg") |
| 206 | + assert os.path.exists(path) |
| 207 | + assert instance.image.medium.width == 400 |
| 208 | + assert instance.image.medium.height <= 400 |
| 209 | + with open(os.path.join(IMG_DIR, "600x400.medium.jpg"), "rb") as f: |
| 210 | + source_file.seek(0) |
| 211 | + assert source_file.read() != f.read() |
| 212 | + |
| 213 | + assert os.path.exists(os.path.join(IMG_DIR, "600x400.thumbnail.jpg")) |
| 214 | + assert instance.image.thumbnail.width == 100 |
| 215 | + assert instance.image.thumbnail.height <= 75 |
| 216 | + with open(os.path.join(IMG_DIR, "600x400.thumbnail.jpg"), "rb") as f: |
| 217 | + source_file.seek(0) |
| 218 | + assert source_file.read() != f.read() |
| 219 | + |
173 | 220 |
|
174 | 221 | class TestUtils(TestStdImage):
|
175 | 222 | """Tests Utils"""
|
|
0 commit comments