diff --git a/tests/integrations/django/myapp/asgi.py b/tests/integrations/django/myapp/asgi.py new file mode 100644 index 0000000000..536753c911 --- /dev/null +++ b/tests/integrations/django/myapp/asgi.py @@ -0,0 +1,19 @@ +""" +ASGI entrypoint. Configures Django and then runs the application +defined in the ASGI_APPLICATION setting. +""" + +import os +import django +from channels.routing import get_default_application + +os.environ.setdefault( + "DJANGO_SETTINGS_MODULE", "tests.integrations.django.myapp.settings" +) + +django.setup() + +from sentry_asgi import SentryMiddleware + +application = get_default_application() +application = SentryMiddleware(application) diff --git a/tests/integrations/django/myapp/manage.py b/tests/integrations/django/myapp/manage.py new file mode 100644 index 0000000000..d65c90e4ee --- /dev/null +++ b/tests/integrations/django/myapp/manage.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault( + "DJANGO_SETTINGS_MODULE", "tests.integrations.django.myapp.settings" + ) + + from django.core.management import execute_from_command_line + +execute_from_command_line(sys.argv) diff --git a/tests/integrations/django/myapp/routing.py b/tests/integrations/django/myapp/routing.py new file mode 100644 index 0000000000..796d3d7d56 --- /dev/null +++ b/tests/integrations/django/myapp/routing.py @@ -0,0 +1,4 @@ +from channels.http import AsgiHandler +from channels.routing import ProtocolTypeRouter + +application = ProtocolTypeRouter({"http": AsgiHandler}) diff --git a/tests/integrations/django/myapp/settings.py b/tests/integrations/django/myapp/settings.py index 4182f669a3..d0c47a001d 100644 --- a/tests/integrations/django/myapp/settings.py +++ b/tests/integrations/django/myapp/settings.py @@ -95,7 +95,7 @@ def process_response(self, request, response): } ] -WSGI_APPLICATION = "tests.django.myapp.wsgi.application" +WSGI_APPLICATION = "tests.integrations.django.myapp.wsgi.application" # Database @@ -150,3 +150,6 @@ def process_response(self, request, response): # https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_URL = "/static/" + +# django-channels specific +ASGI_APPLICATION = "tests.integrations.django.myapp.routing.application" diff --git a/tests/integrations/django/myapp/urls.py b/tests/integrations/django/myapp/urls.py index 934fa65fae..11cc157101 100644 --- a/tests/integrations/django/myapp/urls.py +++ b/tests/integrations/django/myapp/urls.py @@ -49,6 +49,7 @@ name="rest_framework_read_body_and_exc", ) ) + urlpatterns.append(path("rest-hello", views.rest_hello, name="rest_hello")) except AttributeError: pass diff --git a/tests/integrations/django/myapp/views.py b/tests/integrations/django/myapp/views.py index 58626811d0..078906d023 100644 --- a/tests/integrations/django/myapp/views.py +++ b/tests/integrations/django/myapp/views.py @@ -16,6 +16,10 @@ def rest_framework_read_body_and_exc(request): request.data 1 / 0 + @api_view(["GET"]) + def rest_hello(request): + return HttpResponse("ok") + except ImportError: pass diff --git a/tests/integrations/django/myapp/wsgi.py b/tests/integrations/django/myapp/wsgi.py index 298524a800..8c01991e9f 100644 --- a/tests/integrations/django/myapp/wsgi.py +++ b/tests/integrations/django/myapp/wsgi.py @@ -11,6 +11,8 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") +os.environ.setdefault( + "DJANGO_SETTINGS_MODULE", "tests.integrations.django.myapp.settings" +) application = get_wsgi_application()