Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Aug 29, 2024
1 parent ae2992a commit 41adbaa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/django_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import django

from .utils import AppServer
from .utils import TEST_FILE_PATH
from .utils import TEST_FILE_PATH, AppServer

ALLOWED_HOSTS = ["*"]

Expand All @@ -29,7 +28,13 @@
else:
STATICFILES_STORAGE = "servestatic.storage.CompressedManifestStaticFilesStorage"

MIDDLEWARE = ["servestatic.middleware.ServeStaticMiddleware"]
MIDDLEWARE = [
"tests.middleware.sync_middleware_1",
"tests.middleware.async_middleware_1",
"servestatic.middleware.ServeStaticMiddleware",
"tests.middleware.sync_middleware_2",
"tests.middleware.async_middleware_2",
]

LOGGING = {
"version": 1,
Expand Down
38 changes: 38 additions & 0 deletions tests/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from asgiref.sync import iscoroutinefunction
from django.utils.decorators import async_only_middleware, sync_only_middleware


@sync_only_middleware
def sync_middleware_1(get_response):
def middleware(request):
response = get_response(request)
return response

return middleware


@async_only_middleware
def async_middleware_1(get_response):
async def middleware(request):
response = await get_response(request)
return response

return middleware


@sync_only_middleware
def sync_middleware_2(get_response):
def middleware(request):
response = get_response(request)
return response

return middleware


@async_only_middleware
def async_middleware_2(get_response):
async def middleware(request):
response = await get_response(request)
return response

return middleware

0 comments on commit 41adbaa

Please sign in to comment.