Skip to content

Commit

Permalink
Fix misnamed class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelhwilliams committed Aug 3, 2024
1 parent e7b8136 commit 1303da4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
12 changes: 12 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements/tests.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
flask-sqlalchemy
pygments
beautifulsoup4
4 changes: 4 additions & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements/typing.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pyright
pytest
types-pygments
flask-sqlalchemy
types-beautifulsoup4
4 changes: 4 additions & 0 deletions requirements/typing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/flask_debugtoolbar/panels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"""
Expand Down
25 changes: 25 additions & 0 deletions tests/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from unittest.mock import MagicMock
from unittest.mock import patch

from bs4 import BeautifulSoup
import pytest
from flask import Flask
from flask import Response
from flask.testing import FlaskClient
from werkzeug.utils import import_string

from flask_debugtoolbar import DebugToolbarExtension

Expand Down Expand Up @@ -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"])

0 comments on commit 1303da4

Please sign in to comment.