Skip to content

Commit 147a449

Browse files
committed
update async panel compatibility tests
1 parent f597083 commit 147a449

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed
Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
11
from django.http import HttpResponse
22
from django.test import AsyncRequestFactory, RequestFactory, TestCase
3-
from django.test.utils import override_settings
43

5-
from debug_toolbar import settings as dt_settings
4+
from debug_toolbar.panels import Panel
65
from debug_toolbar.toolbar import DebugToolbar
76

87

9-
def set_custom_toolbar_config():
10-
"""
11-
Set custom toolbar configuration.
8+
class MockAsyncPanel(Panel):
9+
is_async = True
1210

13-
Returns a new configuration with DISABLE_PANELS set to an empty dictionary.
14-
This allows all panels to be enabled by default.
15-
"""
16-
new_settings = dt_settings.get_config().copy()
17-
new_settings["DISABLE_PANELS"] = {}
18-
return new_settings
11+
12+
class MockSyncPanel(Panel):
13+
is_async = False
1914

2015

2116
class PanelAsyncCompatibilityTestCase(TestCase):
2217
def setUp(self):
23-
self.factory = AsyncRequestFactory()
24-
self.request = self.factory.get("/")
25-
self.toolbar = None
26-
27-
@override_settings(DEBUG_TOOLBAR_CONFIG=set_custom_toolbar_config())
28-
def test_async_panel_enabling_with_asgi(self):
29-
self.toolbar = DebugToolbar(self.request, lambda request: HttpResponse())
30-
for panel in self.toolbar.panels:
31-
panel.is_async = False
32-
self.assertFalse(panel.enabled)
33-
panel.is_async = True
34-
self.assertTrue(panel.enabled)
35-
36-
@override_settings(DEBUG_TOOLBAR_CONFIG=set_custom_toolbar_config())
37-
def test_enable_all_panels_with_wsgi(self):
38-
self.factory = RequestFactory()
39-
self.request = self.factory.get("/")
40-
self.toolbar = DebugToolbar(self.request, lambda request: HttpResponse())
41-
for panel in self.toolbar.panels:
42-
panel.is_async = True
43-
self.assertTrue(panel.enabled)
44-
panel.is_async = False
45-
self.assertTrue(panel.enabled)
18+
self.async_factory = AsyncRequestFactory()
19+
self.wsgi_factory = RequestFactory()
20+
21+
def test_panels_with_asgi(self):
22+
async_request = self.async_factory.get("/")
23+
toolbar = DebugToolbar(async_request, lambda request: HttpResponse())
24+
25+
async_panel = MockAsyncPanel(toolbar, async_request)
26+
sync_panel = MockSyncPanel(toolbar, async_request)
27+
28+
self.assertTrue(async_panel.enabled)
29+
self.assertFalse(sync_panel.enabled)
30+
31+
def test_panels_with_wsgi(self):
32+
wsgi_request = self.wsgi_factory.get("/")
33+
toolbar = DebugToolbar(wsgi_request, lambda request: HttpResponse())
34+
35+
async_panel = MockAsyncPanel(toolbar, wsgi_request)
36+
sync_panel = MockSyncPanel(toolbar, wsgi_request)
37+
38+
self.assertTrue(async_panel.enabled)
39+
self.assertTrue(sync_panel.enabled)

0 commit comments

Comments
 (0)