Skip to content

Commit

Permalink
trial config of async env for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salty-ivy committed Sep 2, 2024
1 parent e355468 commit d951d34
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ def __call__(self, request):
return self._postprocess(request, response, toolbar)

async def __acall__(self, request):
# A flag to check if all the client calls are going through acall
# and envirnemnt is truely async

print("__acall__ ran!")

# Decide whether the toolbar is active for this request.
show_toolbar = get_show_toolbar()
if not show_toolbar(request) or DebugToolbar.is_toolbar_request(request):
Expand Down
9 changes: 9 additions & 0 deletions tests/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""ASGI config for testing."""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")

application = get_asgi_application()
3 changes: 3 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Application definition

INSTALLED_APPS = [
"daphne",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -30,6 +31,8 @@
"tests",
]

ASGI_APPLICATION = "tests.asgi.application"

USE_GIS = os.getenv("DB_BACKEND") == "postgis"

if USE_GIS:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,16 @@ def test_concurrent_async_sql_page(self):
@override_settings(DEBUG=True)
class DebugToolbarIntegrationTestCase(IntegrationTestCase):
def test_middleware(self):
print("testing middleware now")
response = self.client.get("/execute_sql/")
self.assertEqual(response.status_code, 200)
self.assertContains(response, "djDebug")

# async def test_middleware_in_async_mode(self):
# response = await self.async_client.get("/execute_sql/")
# self.assertEqual(response.status_code, 200)
# self.assertContains(response, "djDebug")

@override_settings(DEFAULT_CHARSET="iso-8859-1")
def test_non_utf8_charset(self):
response = self.client.get("/regular/ASCII/")
Expand Down

0 comments on commit d951d34

Please sign in to comment.