Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge 9998365 into ced213e
Browse files Browse the repository at this point in the history
  • Loading branch information
johananl committed Jan 29, 2018
2 parents ced213e + 9998365 commit df44a23
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.egg-info
/static/
/static_root/
.idea
20 changes: 13 additions & 7 deletions collectfast/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from multiprocessing.dummy import Pool
import warnings

from django.conf import settings as django_settings
from django.contrib.staticfiles.management.commands import collectstatic
from django.utils.encoding import smart_str

Expand Down Expand Up @@ -32,13 +33,18 @@ def __init__(self, *args, **kwargs):
self.tasks = []
self.etags = {}
self.collectfast_enabled = settings.enabled
if self.storage.preload_metadata is not True:
self.storage.preload_metadata = True
warnings.warn(
"Collectfast does not work properly without "
"`preload_metadata` set to `True` on the storage class. Try "
"setting `AWS_PRELOAD_METADATA` to `True`. Overriding "
"`storage.preload_metadata` and continuing.")
if settings.enabled:
if django_settings.STATICFILES_STORAGE in ['storages.backends.s3boto3.S3Boto3Storage',
'storages.backends.s3boto.S3BotoStorage']:
if self.storage.preload_metadata is not True:
self.storage.preload_metadata = True
warnings.warn(
"Collectfast does not work properly without "
"`preload_metadata` set to `True` on the storage class. Try "
"setting `AWS_PRELOAD_METADATA` to `True`. Overriding "
"`storage.preload_metadata` and continuing.")
else:
raise RuntimeError('Collectfast is intended to work with an S3 storage backend only.')

def set_options(self, **options):
"""
Expand Down
29 changes: 29 additions & 0 deletions collectfast/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.core.management import call_command
from django.utils.six import StringIO
from django.test import override_settings as override_django_setting
from mock import patch

from .utils import test, clean_static_dir, create_static_file, override_setting
Expand Down Expand Up @@ -62,6 +63,34 @@ def test_collectfast_disabled(case):
call_collectstatic()


@test
@override_django_setting(
STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage'
)
@override_setting("enabled", False)
@with_bucket
def test_non_s3_storage(case):
clean_static_dir()
create_static_file()
call_collectstatic()


@test
@override_django_setting(
STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage'
)
@with_bucket
def test_enabled_with_non_s3_storage(case):
"""
Running collectfast in enabled mode with a storage type other than S3 should
exit with an error.
"""
clean_static_dir()
create_static_file()
with case.assertRaises(RuntimeError):
call_collectstatic()


@test
@with_bucket
def test_disable_collectfast(case):
Expand Down

0 comments on commit df44a23

Please sign in to comment.