Skip to content

Commit

Permalink
Fixed #25784 -- Prevented an exception on collectstatic help
Browse files Browse the repository at this point in the history
Made the `manage.py help collectstatic` don't fail if the `STATIC_ROOT`
setting is empty.
  • Loading branch information
alexmorozov authored and claudep committed Nov 22, 2015
1 parent 550107f commit 6ca163d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management.color import no_style
from django.utils.encoding import smart_text
from django.utils.functional import cached_property
from django.utils.six.moves import input


Expand All @@ -28,12 +29,14 @@ def __init__(self, *args, **kwargs):
self.post_processed_files = []
self.storage = staticfiles_storage
self.style = no_style()

@cached_property
def local(self):
try:
self.storage.path('')
except NotImplementedError:
self.local = False
else:
self.local = True
return False
return True

def add_arguments(self, parser):
parser.add_argument('--noinput', '--no-input',
Expand Down
14 changes: 14 additions & 0 deletions tests/staticfiles_tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import tempfile
import unittest

from admin_scripts.tests import AdminScriptTestCase

from django.conf import settings
from django.contrib.staticfiles import storage
from django.contrib.staticfiles.management.commands import collectstatic
Expand Down Expand Up @@ -130,6 +132,18 @@ def test_local_storage_detection_helper(self):
storage.staticfiles_storage = staticfiles_storage


class TestCollectionHelpSubcommand(AdminScriptTestCase):
@override_settings(STATIC_ROOT=None)
def test_missing_settings_dont_prevent_help(self):
"""
Even if the STATIC_ROOT setting is not set, one can still call the
`manage.py help collectstatic` command.
"""
self.write_settings('settings.py', apps=['django.contrib.staticfiles'])
out, err = self.run_manage(['help', 'collectstatic'])
self.assertNoOutput(err)


class TestCollection(CollectionTestCase, TestDefaults):
"""
Test ``collectstatic`` management command.
Expand Down

0 comments on commit 6ca163d

Please sign in to comment.