diff --git a/debug_toolbar/panels/staticfiles.py b/debug_toolbar/panels/staticfiles.py index 5f9efb5c3..2eed2efa0 100644 --- a/debug_toolbar/panels/staticfiles.py +++ b/debug_toolbar/panels/staticfiles.py @@ -4,7 +4,6 @@ from django.conf import settings from django.contrib.staticfiles import finders, storage -from django.core.checks import Warning from django.utils.functional import LazyObject from django.utils.translation import gettext_lazy as _, ngettext @@ -178,27 +177,3 @@ def get_staticfiles_apps(self): if app not in apps: apps.append(app) return apps - - @classmethod - def run_checks(cls): - """ - Check that the integration is configured correctly for the panel. - - Specifically look for static files that haven't been collected yet. - - Return a list of :class: `django.core.checks.CheckMessage` instances. - """ - errors = [] - for finder in finders.get_finders(): - try: - for path, finder_storage in finder.list([]): - finder_storage.path(path) - except OSError: - errors.append( - Warning( - "debug_toolbar requires the STATICFILES_DIRS directories to exist.", - hint="Running manage.py collectstatic may help uncover the issue.", - id="debug_toolbar.staticfiles.W001", - ) - ) - return errors diff --git a/docs/changes.rst b/docs/changes.rst index fd79230af..5e6fbb24d 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -13,6 +13,10 @@ Pending * Stayed on top of pre-commit hook updates. * Added :doc:`architecture documentation ` to help on-board new contributors. +* Removed the static file path validation check in + :class:`StaticFilesPanel ` + since that check is made redundant by a similar check in Django 4.0 and + later. 4.3.0 (2024-02-01) ------------------ diff --git a/tests/panels/test_staticfiles.py b/tests/panels/test_staticfiles.py index 32ed7ea61..0736d86ed 100644 --- a/tests/panels/test_staticfiles.py +++ b/tests/panels/test_staticfiles.py @@ -1,15 +1,8 @@ -import os -import unittest - -import django from django.conf import settings from django.contrib.staticfiles import finders -from django.test.utils import override_settings from ..base import BaseTestCase -PATH_DOES_NOT_EXIST = os.path.join(settings.BASE_DIR, "tests", "invalid_static") - class StaticFilesPanelTestCase(BaseTestCase): panel_id = "StaticFilesPanel" @@ -52,33 +45,3 @@ def test_insert_content(self): "django.contrib.staticfiles.finders.AppDirectoriesFinder", content ) self.assertValidHTML(content) - - @unittest.skipIf(django.VERSION >= (4,), "Django>=4 handles missing dirs itself.") - @override_settings( - STATICFILES_DIRS=[PATH_DOES_NOT_EXIST] + settings.STATICFILES_DIRS, - STATIC_ROOT=PATH_DOES_NOT_EXIST, - ) - def test_finder_directory_does_not_exist(self): - """Misconfigure the static files settings and verify the toolbar runs. - - The test case is that the STATIC_ROOT is in STATICFILES_DIRS and that - the directory of STATIC_ROOT does not exist. - """ - response = self.panel.process_request(self.request) - self.panel.generate_stats(self.request, response) - content = self.panel.content - self.assertIn( - "django.contrib.staticfiles.finders.AppDirectoriesFinder", content - ) - self.assertNotIn( - "django.contrib.staticfiles.finders.FileSystemFinder (2 files)", content - ) - self.assertEqual(self.panel.num_used, 0) - self.assertNotEqual(self.panel.num_found, 0) - expected_apps = ["django.contrib.admin", "debug_toolbar"] - if settings.USE_GIS: - expected_apps = ["django.contrib.gis"] + expected_apps - self.assertEqual(self.panel.get_staticfiles_apps(), expected_apps) - self.assertEqual( - self.panel.get_staticfiles_dirs(), finders.FileSystemFinder().locations - ) diff --git a/tests/test_checks.py b/tests/test_checks.py index 8e4f8e62f..b88787f9d 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -1,14 +1,8 @@ -import os -import unittest from unittest.mock import patch -import django -from django.conf import settings from django.core.checks import Warning, run_checks from django.test import SimpleTestCase, override_settings -PATH_DOES_NOT_EXIST = os.path.join(settings.BASE_DIR, "tests", "invalid_static") - class ChecksTestCase(SimpleTestCase): @override_settings( @@ -92,23 +86,6 @@ def test_check_middleware_classes_error(self): messages, ) - @unittest.skipIf(django.VERSION >= (4,), "Django>=4 handles missing dirs itself.") - @override_settings( - STATICFILES_DIRS=[PATH_DOES_NOT_EXIST], - ) - def test_panel_check_errors(self): - messages = run_checks() - self.assertEqual( - messages, - [ - Warning( - "debug_toolbar requires the STATICFILES_DIRS directories to exist.", - hint="Running manage.py collectstatic may help uncover the issue.", - id="debug_toolbar.staticfiles.W001", - ) - ], - ) - @override_settings(DEBUG_TOOLBAR_PANELS=[]) def test_panels_is_empty(self): errors = run_checks()