mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #29966 -- Added tests for BaseHandler's "The view didn't return an HttpResponse object" error.
This commit is contained in:
parent
fc71bb11b1
commit
11a9017179
@ -189,6 +189,16 @@ class HandlerRequestTests(SimpleTestCase):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
self.client.get('/')
|
||||
|
||||
def test_no_response(self):
|
||||
msg = "The view %s didn't return an HttpResponse object. It returned None instead."
|
||||
tests = (
|
||||
('/no_response_fbv/', 'handlers.views.no_response'),
|
||||
('/no_response_cbv/', 'handlers.views.NoResponse.__call__'),
|
||||
)
|
||||
for url, view in tests:
|
||||
with self.subTest(url=url), self.assertRaisesMessage(ValueError, msg % view):
|
||||
self.client.get(url)
|
||||
|
||||
|
||||
class ScriptNameTests(SimpleTestCase):
|
||||
def test_get_script_name(self):
|
||||
|
@ -1,9 +1,12 @@
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^regular/$', views.regular),
|
||||
path('no_response_fbv/', views.no_response),
|
||||
path('no_response_cbv/', views.NoResponse()),
|
||||
url(r'^streaming/$', views.streaming),
|
||||
url(r'^in_transaction/$', views.in_transaction),
|
||||
url(r'^not_in_transaction/$', views.not_in_transaction),
|
||||
|
@ -10,6 +10,15 @@ def regular(request):
|
||||
return HttpResponse(b"regular content")
|
||||
|
||||
|
||||
def no_response(request):
|
||||
pass
|
||||
|
||||
|
||||
class NoResponse:
|
||||
def __call__(self, request):
|
||||
pass
|
||||
|
||||
|
||||
def streaming(request):
|
||||
return StreamingHttpResponse([b"streaming", b" ", b"content"])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user