django-imagekit/tests/test_serialization.py

44 lines
1.2 KiB
Python
Raw Permalink Normal View History

2012-11-06 03:44:00 +00:00
"""
Make sure that the various IK classes can be successfully serialized and
deserialized. This is important when using IK with Celery.
"""
from imagekit.cachefiles import ImageCacheFile
from .imagegenerators import TestSpec
2016-07-17 01:43:04 +00:00
from .utils import create_photo, pickleback, get_unique_image_file, clear_imagekit_cache
2012-11-06 03:44:00 +00:00
def test_imagespecfield():
2016-07-17 01:43:04 +00:00
clear_imagekit_cache()
2012-11-06 03:44:00 +00:00
instance = create_photo('pickletest2.jpg')
thumbnail = pickleback(instance.thumbnail)
2012-12-05 05:44:16 +00:00
thumbnail.generate()
2013-07-13 20:38:49 +00:00
def test_circular_ref():
"""
A model instance with a spec field in its dict shouldn't raise a KeyError.
This corresponds to #234
"""
2016-07-17 01:43:04 +00:00
clear_imagekit_cache()
2013-07-13 20:38:49 +00:00
instance = create_photo('pickletest3.jpg')
instance.thumbnail # Cause thumbnail to be added to instance's __dict__
pickleback(instance)
2016-07-17 01:43:04 +00:00
def test_cachefiles():
2016-07-17 01:43:04 +00:00
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