From 87faeee4e0c0eb3937e2e575794f4512e513d214 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Wed, 6 May 2020 22:29:32 +0200 Subject: [PATCH] Fixed #31528 -- Made collectstatic management command run staticfiles checks. --- .../staticfiles/management/commands/collectstatic.py | 7 +++++++ tests/staticfiles_tests/test_management.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index 9c90fb09b4..ff630fd413 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -3,6 +3,7 @@ import os from django.apps import apps from django.contrib.staticfiles.finders import get_finders from django.contrib.staticfiles.storage import staticfiles_storage +from django.core.checks import Tags from django.core.files.storage import FileSystemStorage from django.core.management.base import BaseCommand, CommandError from django.core.management.color import no_style @@ -35,6 +36,10 @@ class Command(BaseCommand): return True def add_arguments(self, parser): + parser.add_argument( + '--skip-checks', action='store_true', + help='Skip system checks.', + ) parser.add_argument( '--noinput', '--no-input', action='store_false', dest='interactive', help="Do NOT prompt the user for input of any kind.", @@ -146,6 +151,8 @@ class Command(BaseCommand): def handle(self, **options): self.set_options(**options) + if not options['skip_checks']: + self.check(tags=[Tags.staticfiles]) message = ['\n'] if self.dry_run: diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 1236d533d3..f249b63140 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -16,6 +16,7 @@ from django.contrib.staticfiles.management.commands import ( ) from django.core.exceptions import ImproperlyConfigured from django.core.management import CommandError, call_command +from django.core.management.base import SystemCheckError from django.test import RequestFactory, override_settings from django.test.utils import extend_sys_path from django.utils import timezone @@ -145,6 +146,12 @@ class TestConfiguration(StaticFilesTestCase): collectstatic.staticfiles_storage = staticfiles_storage storage.staticfiles_storage = staticfiles_storage + @override_settings(STATICFILES_DIRS=('test')) + def test_collectstatis_check(self): + msg = 'The STATICFILES_DIRS setting is not a tuple or list.' + with self.assertRaisesMessage(SystemCheckError, msg): + call_command('collectstatic', skip_checks=False) + class TestCollectionHelpSubcommand(AdminScriptTestCase): @override_settings(STATIC_ROOT=None)