Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that Optimistic strategy doesn't cause reads
Using the Optimistic strategy should prevent IO ops when you cast the file as a boolean.
- Loading branch information
1 parent
9f4192a
commit c92f53c
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from nose.tools import assert_true, assert_false | ||
from imagekit.cachefiles import ImageCacheFile | ||
from mock import Mock | ||
from .utils import create_image | ||
from django.core.files.storage import FileSystemStorage | ||
from imagekit.cachefiles.backends import Simple as SimpleCFBackend | ||
from imagekit.cachefiles.strategies import Optimistic as OptimisticStrategy | ||
|
||
|
||
class ImageGenerator(object): | ||
def generate(self): | ||
return create_image() | ||
|
||
def get_hash(self): | ||
return 'abc123' | ||
|
||
|
||
def get_image_cache_file(): | ||
storage = Mock(FileSystemStorage) | ||
backend = SimpleCFBackend() | ||
strategy = OptimisticStrategy() | ||
generator = ImageGenerator() | ||
return ImageCacheFile(generator, storage=storage, | ||
cachefile_backend=backend, | ||
cachefile_strategy=strategy) | ||
|
||
|
||
def test_no_io_on_bool(): | ||
""" | ||
When checking the truthiness of an ImageCacheFile, the storage shouldn't | ||
peform IO operations. | ||
""" | ||
file = get_image_cache_file() | ||
bool(file) | ||
assert_false(file.storage.exists.called) | ||
assert_false(file.storage.open.called) |