1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
from django.test import override_settings
from debug_toolbar.panels import Panel
from ..base import IntegrationTestCase
class CustomPanel(Panel):
def title(self):
return "Title with special chars &\"'<>"
@override_settings(
DEBUG=True, DEBUG_TOOLBAR_PANELS=["tests.panels.test_custom.CustomPanel"]
)
class CustomPanelTestCase(IntegrationTestCase):
def test_escapes_panel_title(self):
response = self.client.get("/regular/basic/")
self.assertContains(
response,
"""
<li id="djdt-CustomPanel" class="djDebugPanelButton">
<input type="checkbox" checked title="Disable for next and successive requests" data-cookie="djdtCustomPanel">
<a class="CustomPanel" href="#" title="Title with special chars &"'<>">
Title with special chars &"'<>
</a>
</li>
""",
html=True,
)
self.assertContains(
response,
"""
<div id="CustomPanel" class="djdt-panelContent djdt-hidden">
<div class="djDebugPanelTitle">
<h3>Title with special chars &"'<></h3>
<button type="button" class="djDebugClose">×</button>
</div>
<div class="djDebugPanelContent">
<div class="djdt-loader"></div>
<div class="djdt-scroll"></div>
</div>
</div>
""",
html=True,
)
|