File: test_async_panel_compatibility.py

package info (click to toggle)
python-django-debug-toolbar 1%3A6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,052 kB
  • sloc: python: 7,555; javascript: 636; makefile: 67; sh: 16
file content (39 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download | duplicates (2)
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
from django.http import HttpResponse
from django.test import AsyncRequestFactory, RequestFactory, TestCase

from debug_toolbar.panels import Panel
from debug_toolbar.toolbar import DebugToolbar


class MockAsyncPanel(Panel):
    is_async = True


class MockSyncPanel(Panel):
    is_async = False


class PanelAsyncCompatibilityTestCase(TestCase):
    def setUp(self):
        self.async_factory = AsyncRequestFactory()
        self.wsgi_factory = RequestFactory()

    def test_panels_with_asgi(self):
        async_request = self.async_factory.get("/")
        toolbar = DebugToolbar(async_request, lambda request: HttpResponse())

        async_panel = MockAsyncPanel(toolbar, async_request)
        sync_panel = MockSyncPanel(toolbar, async_request)

        self.assertTrue(async_panel.enabled)
        self.assertFalse(sync_panel.enabled)

    def test_panels_with_wsgi(self):
        wsgi_request = self.wsgi_factory.get("/")
        toolbar = DebugToolbar(wsgi_request, lambda request: HttpResponse())

        async_panel = MockAsyncPanel(toolbar, wsgi_request)
        sync_panel = MockSyncPanel(toolbar, wsgi_request)

        self.assertTrue(async_panel.enabled)
        self.assertTrue(sync_panel.enabled)