diff --git a/tests/test_main.py b/tests/test_main.py index ee552f4..aa744a3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,4 +1,5 @@ import json +import logging import pytest from asgiref.sync import sync_to_async @@ -338,6 +339,23 @@ async def test_remote_addr_another(self, async_client): event = await RequestEvent.objects.aget(url=reverse("test_app:index")) assert event.remote_ip == "10.0.0.1" + async def test_middleware_is_async_capable(self, async_client, caplog, settings): + """Test for async capability of EasyAuditMiddleware. + + If the EasyAuditMiddleware is async capable Django `django.request` logger + will not emit debug message 'Asynchronous handler adapted for middleware …' + + See: https://docs.djangoproject.com/en/5.0/topics/async/#async-views + """ + unwanted_log_message = ( + "Asynchronous handler adapted for middleware " + "easyaudit.middleware.easyaudit.EasyAuditMiddleware" + ) + settings.DEBUG = True + with caplog.at_level(logging.DEBUG, "django.request"): + await async_client.get(reverse("test_app:index")) + assert unwanted_log_message not in caplog.text + @pytest.mark.django_db class TestWSGIRequestEvent: