Fixed #29966 -- Added tests for BaseHandler's "The view didn't return an HttpResponse object" error.

This commit is contained in:
Hasan Ramezani 2018-11-24 01:19:02 +01:00 committed by Tim Graham
parent fc71bb11b1
commit 11a9017179
3 changed files with 22 additions and 0 deletions

View File

@ -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):

View File

@ -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),

View File

@ -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"])