Skip to content

Commit cc48a14

Browse files
committed
Remove obsolete staticfiles check
The toolbar had a check for misconfigured static files directories. However, Django 4.0 added its own check for this situation. Since the toolbar's minimum supported Django version is now 4.2, the toolbar's check is made redundant by Django's check and can thus be removed.
1 parent 0baef8c commit cc48a14

File tree

4 files changed

+4
-85
lines changed

4 files changed

+4
-85
lines changed

debug_toolbar/panels/staticfiles.py

-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from django.conf import settings
66
from django.contrib.staticfiles import finders, storage
7-
from django.core.checks import Warning
87
from django.utils.functional import LazyObject
98
from django.utils.translation import gettext_lazy as _, ngettext
109

@@ -178,27 +177,3 @@ def get_staticfiles_apps(self):
178177
if app not in apps:
179178
apps.append(app)
180179
return apps
181-
182-
@classmethod
183-
def run_checks(cls):
184-
"""
185-
Check that the integration is configured correctly for the panel.
186-
187-
Specifically look for static files that haven't been collected yet.
188-
189-
Return a list of :class: `django.core.checks.CheckMessage` instances.
190-
"""
191-
errors = []
192-
for finder in finders.get_finders():
193-
try:
194-
for path, finder_storage in finder.list([]):
195-
finder_storage.path(path)
196-
except OSError:
197-
errors.append(
198-
Warning(
199-
"debug_toolbar requires the STATICFILES_DIRS directories to exist.",
200-
hint="Running manage.py collectstatic may help uncover the issue.",
201-
id="debug_toolbar.staticfiles.W001",
202-
)
203-
)
204-
return errors

docs/changes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Pending
1313
* Stayed on top of pre-commit hook updates.
1414
* Added :doc:`architecture documentation <architecture>` to help
1515
on-board new contributors.
16+
* Removed the static file path validation check in
17+
:class:`StaticFilesPanel <debug_toolbar.panels.staticfiles.StaticFilesPanel>`
18+
since that check is made redundant by a similar check in Django 4.0 and
19+
later.
1620

1721
4.3.0 (2024-02-01)
1822
------------------

tests/panels/test_staticfiles.py

-37
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import os
2-
import unittest
3-
4-
import django
51
from django.conf import settings
62
from django.contrib.staticfiles import finders
7-
from django.test.utils import override_settings
83

94
from ..base import BaseTestCase
105

11-
PATH_DOES_NOT_EXIST = os.path.join(settings.BASE_DIR, "tests", "invalid_static")
12-
136

147
class StaticFilesPanelTestCase(BaseTestCase):
158
panel_id = "StaticFilesPanel"
@@ -52,33 +45,3 @@ def test_insert_content(self):
5245
"django.contrib.staticfiles.finders.AppDirectoriesFinder", content
5346
)
5447
self.assertValidHTML(content)
55-
56-
@unittest.skipIf(django.VERSION >= (4,), "Django>=4 handles missing dirs itself.")
57-
@override_settings(
58-
STATICFILES_DIRS=[PATH_DOES_NOT_EXIST] + settings.STATICFILES_DIRS,
59-
STATIC_ROOT=PATH_DOES_NOT_EXIST,
60-
)
61-
def test_finder_directory_does_not_exist(self):
62-
"""Misconfigure the static files settings and verify the toolbar runs.
63-
64-
The test case is that the STATIC_ROOT is in STATICFILES_DIRS and that
65-
the directory of STATIC_ROOT does not exist.
66-
"""
67-
response = self.panel.process_request(self.request)
68-
self.panel.generate_stats(self.request, response)
69-
content = self.panel.content
70-
self.assertIn(
71-
"django.contrib.staticfiles.finders.AppDirectoriesFinder", content
72-
)
73-
self.assertNotIn(
74-
"django.contrib.staticfiles.finders.FileSystemFinder (2 files)", content
75-
)
76-
self.assertEqual(self.panel.num_used, 0)
77-
self.assertNotEqual(self.panel.num_found, 0)
78-
expected_apps = ["django.contrib.admin", "debug_toolbar"]
79-
if settings.USE_GIS:
80-
expected_apps = ["django.contrib.gis"] + expected_apps
81-
self.assertEqual(self.panel.get_staticfiles_apps(), expected_apps)
82-
self.assertEqual(
83-
self.panel.get_staticfiles_dirs(), finders.FileSystemFinder().locations
84-
)

tests/test_checks.py

-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import os
2-
import unittest
31
from unittest.mock import patch
42

5-
import django
6-
from django.conf import settings
73
from django.core.checks import Warning, run_checks
84
from django.test import SimpleTestCase, override_settings
95

10-
PATH_DOES_NOT_EXIST = os.path.join(settings.BASE_DIR, "tests", "invalid_static")
11-
126

137
class ChecksTestCase(SimpleTestCase):
148
@override_settings(
@@ -92,23 +86,6 @@ def test_check_middleware_classes_error(self):
9286
messages,
9387
)
9488

95-
@unittest.skipIf(django.VERSION >= (4,), "Django>=4 handles missing dirs itself.")
96-
@override_settings(
97-
STATICFILES_DIRS=[PATH_DOES_NOT_EXIST],
98-
)
99-
def test_panel_check_errors(self):
100-
messages = run_checks()
101-
self.assertEqual(
102-
messages,
103-
[
104-
Warning(
105-
"debug_toolbar requires the STATICFILES_DIRS directories to exist.",
106-
hint="Running manage.py collectstatic may help uncover the issue.",
107-
id="debug_toolbar.staticfiles.W001",
108-
)
109-
],
110-
)
111-
11289
@override_settings(DEBUG_TOOLBAR_PANELS=[])
11390
def test_panels_is_empty(self):
11491
errors = run_checks()

0 commit comments

Comments
 (0)