From 43b7ad89fd52492b53cb5c9a780196d43bea71ee Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Tue, 22 Jul 2025 16:25:30 +0200 Subject: [PATCH] Fixes #2158 -- Made static file objects orderable --- debug_toolbar/panels/staticfiles.py | 2 +- tests/panels/test_staticfiles.py | 14 ++++++++++---- tests/templates/staticfiles/path.html | 4 +--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/debug_toolbar/panels/staticfiles.py b/debug_toolbar/panels/staticfiles.py index fb2cdd093..1dc61c1e4 100644 --- a/debug_toolbar/panels/staticfiles.py +++ b/debug_toolbar/panels/staticfiles.py @@ -11,7 +11,7 @@ from debug_toolbar import panels -@dataclass(eq=True, frozen=True) +@dataclass(eq=True, frozen=True, order=True) class StaticFile: """ Representing the different properties of a static file. diff --git a/tests/panels/test_staticfiles.py b/tests/panels/test_staticfiles.py index 81afe6afa..9af7e5bf8 100644 --- a/tests/panels/test_staticfiles.py +++ b/tests/panels/test_staticfiles.py @@ -65,19 +65,25 @@ def test_insert_content(self): def test_path(self): def get_response(request): - # template contains one static file return render( request, "staticfiles/path.html", - {"path": Path("additional_static/base.css")}, + { + "paths": [ + Path("additional_static/base.css"), + Path("additional_static/base.css"), + Path("additional_static/base2.css"), + ] + }, ) self._get_response = get_response request = RequestFactory().get("/") response = self.panel.process_request(request) self.panel.generate_stats(self.request, response) - self.assertEqual(self.panel.get_stats()["num_used"], 1) - self.assertIn('"/static/additional_static/base.css"', self.panel.content) + self.assertEqual(self.panel.get_stats()["num_used"], 2) + self.assertIn('"/static/additional_static/base.css"', self.panel.content, 1) + self.assertIn('"/static/additional_static/base2.css"', self.panel.content, 1) def test_storage_state_preservation(self): """Ensure the URLMixin doesn't affect storage state""" diff --git a/tests/templates/staticfiles/path.html b/tests/templates/staticfiles/path.html index 9e9ff1b88..d56123afb 100644 --- a/tests/templates/staticfiles/path.html +++ b/tests/templates/staticfiles/path.html @@ -1,3 +1 @@ -{% load static %} -{# A single file used twice #} -{% static path %}{% static path %} +{% load static %}{% for path in paths %}{% static path %}{% endfor %}