diff --git a/requirements/dev.txt b/requirements/dev.txt index c359ed2..2a9facc 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,6 +12,8 @@ babel==2.14.0 # via # -r docs.txt # sphinx +beautifulsoup4==4.12.3 + # via -r tests.txt blinker==1.8.1 # via # -r tests.txt @@ -170,6 +172,10 @@ snowballstemmer==2.2.0 # via # -r docs.txt # sphinx +soupsieve==2.5 + # via + # -r tests.txt + # beautifulsoup4 sphinx==7.1.2 # via # -r docs.txt @@ -216,10 +222,16 @@ tomli==2.0.1 # tox tox==4.15.1 # via -r dev.in +types-beautifulsoup4==4.12.0.20240511 + # via -r typing.txt types-docutils==0.21.0.20240423 # via # -r typing.txt # types-pygments +types-html5lib==1.1.11.20240228 + # via + # -r typing.txt + # types-beautifulsoup4 types-pygments==2.18.0.20240506 # via -r typing.txt types-setuptools==69.5.0.20240423 diff --git a/requirements/tests.in b/requirements/tests.in index 1850600..da48c5c 100644 --- a/requirements/tests.in +++ b/requirements/tests.in @@ -1,3 +1,4 @@ pytest flask-sqlalchemy pygments +beautifulsoup4 diff --git a/requirements/tests.txt b/requirements/tests.txt index aa9a4dd..d2c64b1 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -4,6 +4,8 @@ # # pip-compile tests.in # +beautifulsoup4==4.12.3 + # via -r tests.in blinker==1.8.1 # via flask click==8.1.7 @@ -36,6 +38,8 @@ pygments==2.18.0 # via -r tests.in pytest==8.3.2 # via -r tests.in +soupsieve==2.5 + # via beautifulsoup4 sqlalchemy==2.0.29 # via flask-sqlalchemy tomli==2.0.1 diff --git a/requirements/typing.in b/requirements/typing.in index 95d459e..b56bd97 100644 --- a/requirements/typing.in +++ b/requirements/typing.in @@ -3,3 +3,4 @@ pyright pytest types-pygments flask-sqlalchemy +types-beautifulsoup4 diff --git a/requirements/typing.txt b/requirements/typing.txt index 8aef481..3f8ca26 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -48,8 +48,12 @@ tomli==2.0.1 # via # mypy # pytest +types-beautifulsoup4==4.12.0.20240511 + # via -r typing.in types-docutils==0.21.0.20240423 # via types-pygments +types-html5lib==1.1.11.20240228 + # via types-beautifulsoup4 types-pygments==2.18.0.20240506 # via -r typing.in types-setuptools==69.5.0.20240423 diff --git a/src/flask_debugtoolbar/panels/__init__.py b/src/flask_debugtoolbar/panels/__init__.py index 9a6486a..7315c99 100644 --- a/src/flask_debugtoolbar/panels/__init__.py +++ b/src/flask_debugtoolbar/panels/__init__.py @@ -18,7 +18,7 @@ class DebugPanel: has_content = False # If the client is able to activate/de-activate the panel - user_enable = False + user_activate = False # We'll maintain a local context instance so we can expose our template # context variables to panels which need them: @@ -62,8 +62,9 @@ def render(self, template_name: str, context: dict[str, t.Any]) -> str: template = self.jinja_env.get_template(template_name) return template.render(**context) - def dom_id(self) -> str: - return f"flDebug{self.name.replace(' ', '')}Panel" + @classmethod + def dom_id(cls) -> str: + return f"flDebug{cls.name.replace(' ', '')}Panel" def nav_title(self) -> str: """Title showing in toolbar""" diff --git a/tests/test_toolbar.py b/tests/test_toolbar.py index 7e974fb..b2ef28e 100644 --- a/tests/test_toolbar.py +++ b/tests/test_toolbar.py @@ -5,9 +5,11 @@ from unittest.mock import patch import pytest +from bs4 import BeautifulSoup from flask import Flask from flask import Response from flask.testing import FlaskClient +from werkzeug.utils import import_string from flask_debugtoolbar import DebugToolbarExtension @@ -165,3 +167,26 @@ def test_toolbar_serves_assets_based_on_host_configuration( "/_debug_toolbar/static/js/toolbar.js", headers={"Host": request_host} ) assert response.status_code == expected_status_code + + +def test_debug_switch_included_for_user_activated_panels() -> None: + checked_panels = set() + + app = load_app("basic_app") + index = app.get("/") + + soup = BeautifulSoup(index.text, "html.parser") + + for panel in app.application.config["DEBUG_TB_PANELS"]: + panel_cls = import_string(panel) + panel_id = panel_cls.dom_id() + panel_element = soup.select_one(f"#{panel_id}") + + assert panel_element + assert ( + bool(panel_element.select_one(".flDebugSwitch")) is panel_cls.user_activate + ), f"Panel {panel_id} is incorrectly showing (or not showing) a debug switch" + + checked_panels.add(panel_id) + + assert len(checked_panels) == len(app.application.config["DEBUG_TB_PANELS"])