Skip to content

Commit a32f41c

Browse files
authored
test: Add Django channels to Django example app (getsentry#428)
See getsentry#419, preparation for getsentry#429
1 parent 71e5cfa commit a32f41c

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
ASGI entrypoint. Configures Django and then runs the application
3+
defined in the ASGI_APPLICATION setting.
4+
"""
5+
6+
import os
7+
import django
8+
from channels.routing import get_default_application
9+
10+
os.environ.setdefault(
11+
"DJANGO_SETTINGS_MODULE", "tests.integrations.django.myapp.settings"
12+
)
13+
14+
django.setup()
15+
16+
from sentry_asgi import SentryMiddleware
17+
18+
application = get_default_application()
19+
application = SentryMiddleware(application)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault(
7+
"DJANGO_SETTINGS_MODULE", "tests.integrations.django.myapp.settings"
8+
)
9+
10+
from django.core.management import execute_from_command_line
11+
12+
execute_from_command_line(sys.argv)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from channels.http import AsgiHandler
2+
from channels.routing import ProtocolTypeRouter
3+
4+
application = ProtocolTypeRouter({"http": AsgiHandler})

tests/integrations/django/myapp/settings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def process_response(self, request, response):
9595
}
9696
]
9797

98-
WSGI_APPLICATION = "tests.django.myapp.wsgi.application"
98+
WSGI_APPLICATION = "tests.integrations.django.myapp.wsgi.application"
9999

100100

101101
# Database
@@ -150,3 +150,6 @@ def process_response(self, request, response):
150150
# https://docs.djangoproject.com/en/2.0/howto/static-files/
151151

152152
STATIC_URL = "/static/"
153+
154+
# django-channels specific
155+
ASGI_APPLICATION = "tests.integrations.django.myapp.routing.application"

tests/integrations/django/myapp/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
name="rest_framework_read_body_and_exc",
5050
)
5151
)
52+
urlpatterns.append(path("rest-hello", views.rest_hello, name="rest_hello"))
5253
except AttributeError:
5354
pass
5455

tests/integrations/django/myapp/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def rest_framework_read_body_and_exc(request):
1616
request.data
1717
1 / 0
1818

19+
@api_view(["GET"])
20+
def rest_hello(request):
21+
return HttpResponse("ok")
22+
1923

2024
except ImportError:
2125
pass

tests/integrations/django/myapp/wsgi.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from django.core.wsgi import get_wsgi_application
1313

14-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
14+
os.environ.setdefault(
15+
"DJANGO_SETTINGS_MODULE", "tests.integrations.django.myapp.settings"
16+
)
1517

1618
application = get_wsgi_application()

0 commit comments

Comments
 (0)