mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
Add tests for cachefile truthiness
This commit is contained in:
parent
1e129c5b70
commit
b061e135c2
2 changed files with 44 additions and 3 deletions
|
|
@ -1,18 +1,41 @@
|
|||
from imagekit.cachefiles import ImageCacheFile
|
||||
from nose.tools import raises
|
||||
from .imagegenerators import TestSpec
|
||||
from .utils import assert_file_is_falsy
|
||||
from .utils import (assert_file_is_truthy, assert_file_is_falsy,
|
||||
DummyAsyncCacheFileBackend, get_unique_image_file)
|
||||
|
||||
|
||||
def test_no_source():
|
||||
def test_no_source_falsiness():
|
||||
"""
|
||||
Ensure sourceless specs are falsy.
|
||||
Ensure cache files generated from sourceless specs are falsy.
|
||||
|
||||
"""
|
||||
spec = TestSpec(source=None)
|
||||
file = ImageCacheFile(spec)
|
||||
assert_file_is_falsy(file)
|
||||
|
||||
|
||||
def test_sync_backend_truthiness():
|
||||
"""
|
||||
Ensure that a cachefile with a synchronous cache file backend (the default)
|
||||
is truthy.
|
||||
|
||||
"""
|
||||
spec = TestSpec(source=get_unique_image_file())
|
||||
file = ImageCacheFile(spec)
|
||||
assert_file_is_truthy(file)
|
||||
|
||||
|
||||
def test_async_backend_falsiness():
|
||||
"""
|
||||
Ensure that a cachefile with an asynchronous cache file backend is falsy.
|
||||
|
||||
"""
|
||||
spec = TestSpec(source=get_unique_image_file())
|
||||
file = ImageCacheFile(spec, cachefile_backend=DummyAsyncCacheFileBackend())
|
||||
assert_file_is_falsy(file)
|
||||
|
||||
|
||||
@raises(TestSpec.MissingSource)
|
||||
def test_no_source_error():
|
||||
spec = TestSpec(source=None)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ import os
|
|||
from django.conf import settings
|
||||
from django.core.files import File
|
||||
from django.template import Context, Template
|
||||
from imagekit.cachefiles.backends import Simple, CacheFileState
|
||||
from imagekit.lib import Image, StringIO
|
||||
from nose.tools import assert_true, assert_false
|
||||
import pickle
|
||||
from tempfile import NamedTemporaryFile
|
||||
from .models import Photo
|
||||
|
||||
|
||||
|
|
@ -21,6 +23,12 @@ def get_image_file():
|
|||
return open(path, 'r+b')
|
||||
|
||||
|
||||
def get_unique_image_file():
|
||||
file = NamedTemporaryFile()
|
||||
file.write(get_image_file().read())
|
||||
return file
|
||||
|
||||
|
||||
def create_image():
|
||||
return Image.open(get_image_file())
|
||||
|
||||
|
|
@ -62,3 +70,13 @@ def assert_file_is_falsy(file):
|
|||
|
||||
def assert_file_is_truthy(file):
|
||||
assert_true(bool(file), 'File is not truthy')
|
||||
|
||||
|
||||
class DummyAsyncCacheFileBackend(Simple):
|
||||
"""
|
||||
A cache file backend meant to simulate async generation (by marking the
|
||||
file as pending but never actually creating it).
|
||||
|
||||
"""
|
||||
def _generate(self, file):
|
||||
self.set_state(file, CacheFileState.PENDING)
|
||||
|
|
|
|||
Loading…
Reference in a new issue