1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
"""
Make sure that the various IK classes can be successfully serialized and
deserialized. This is important when using IK with Celery.
"""
import pytest
from imagekit.cachefiles import ImageCacheFile
from .imagegenerators import TestSpec
from .utils import (clear_imagekit_cache, create_photo, get_unique_image_file,
pickleback)
@pytest.mark.django_db(transaction=True)
def test_imagespecfield():
clear_imagekit_cache()
instance = create_photo('pickletest2.jpg')
thumbnail = pickleback(instance.thumbnail)
thumbnail.generate()
@pytest.mark.django_db(transaction=True)
def test_circular_ref():
"""
A model instance with a spec field in its dict shouldn't raise a KeyError.
This corresponds to #234
"""
clear_imagekit_cache()
instance = create_photo('pickletest3.jpg')
instance.thumbnail # Cause thumbnail to be added to instance's __dict__
pickleback(instance)
def test_cachefiles():
clear_imagekit_cache()
spec = TestSpec(source=get_unique_image_file())
file = ImageCacheFile(spec)
file.url
# remove link to file from spec source generator
# test __getstate__ of ImageCacheFile
file.generator.source = None
restored_file = pickleback(file)
assert file is not restored_file
# Assertion for #437 and #451
assert file.storage is restored_file.storage
|