|
1 | 1 | from django.http import HttpResponse |
2 | 2 | from django.test import AsyncRequestFactory, RequestFactory, TestCase |
3 | | -from django.test.utils import override_settings |
4 | 3 |
|
5 | | -from debug_toolbar import settings as dt_settings |
| 4 | +from debug_toolbar.panels import Panel |
6 | 5 | from debug_toolbar.toolbar import DebugToolbar |
7 | 6 |
|
8 | 7 |
|
9 | | -def set_custom_toolbar_config(): |
10 | | - """ |
11 | | - Set custom toolbar configuration. |
| 8 | +class MockAsyncPanel(Panel): |
| 9 | + is_async = True |
12 | 10 |
|
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 |
19 | 14 |
|
20 | 15 |
|
21 | 16 | class PanelAsyncCompatibilityTestCase(TestCase): |
22 | 17 | 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