diff --git a/stdimage/management/commands/rendervariations.py b/stdimage/management/commands/rendervariations.py index e1c4eb0..0f8de6c 100644 --- a/stdimage/management/commands/rendervariations.py +++ b/stdimage/management/commands/rendervariations.py @@ -16,10 +16,6 @@ BAR = None -def class_to_path(cls): - return '.'.join((cls.__module__, cls.__class__.__name__)) - - class MemoryUsageWidget(progressbar.widgets.WidgetBase): def __call__(self, progress, data): return 'RAM: {0:10.1f} MB'.format( @@ -64,7 +60,7 @@ def render(field, images, count, replace): file_name=file_name, variations=field.variations, replace=replace, - storage=class_to_path(field.storage), + storage=field.storage.deconstruct()[0], ) for file_name in images ] diff --git a/tests/models.py b/tests/models.py index 736a1ac..1471a24 100644 --- a/tests/models.py +++ b/tests/models.py @@ -1,3 +1,4 @@ +from django.core.files.storage import FileSystemStorage from django.db import models from django.db.models.signals import post_delete, pre_save @@ -104,6 +105,16 @@ class ManualVariationsModel(CustomManagerModel): ) +class MyStorageModel(CustomManagerModel): + """delays creation of 150x150 thumbnails until it is called manually""" + image = StdImageField( + upload_to=UploadTo(name='image', path='img'), + variations={'thumbnail': (150, 150, True)}, + render_variations=False, + storage=FileSystemStorage(), + ) + + def render_job(**kwargs): render_variations(**kwargs) return False diff --git a/tests/settings.py b/tests/settings.py index 674f7c9..4fadc8b 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -23,6 +23,8 @@ 'tests' ) +DEFAULT_FILE_STORAGE = 'tests.storage.MyFileSystemStorage' + MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', diff --git a/tests/storage.py b/tests/storage.py new file mode 100644 index 0000000..3a6c3ee --- /dev/null +++ b/tests/storage.py @@ -0,0 +1,5 @@ +from django.core.files.storage import FileSystemStorage + + +class MyFileSystemStorage(FileSystemStorage): + pass diff --git a/tests/test_commands.py b/tests/test_commands.py index 99883c8..9f209e0 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -4,7 +4,7 @@ import pytest from django.core.management import call_command -from tests.models import ManualVariationsModel, ThumbnailModel +from tests.models import ManualVariationsModel, MyStorageModel, ThumbnailModel @pytest.mark.django_db @@ -62,3 +62,14 @@ def test_replace(self, image_upload_file): assert os.path.exists(file_path) after = os.path.getmtime(file_path) assert before != after + + def test_none_default_storage(self, image_upload_file): + obj = MyStorageModel.customer_manager.create( + image=image_upload_file + ) + file_path = obj.image.thumbnail.path + call_command( + 'rendervariations', + 'tests.MyStorageModel.image' + ) + assert os.path.exists(file_path)