diff options
author | Hasan Ramezani <hasan.r67@gmail.com> | 2018-11-24 01:19:02 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-11-23 19:19:02 -0500 |
commit | 11a9017179812198a12a2fc19610262a549aa46e (patch) | |
tree | a9fd5c930c619e6d5d2824b716c24c93a43e02f9 /tests/handlers | |
parent | fc71bb11b164c68ad952cb5c3048fc858e6bc61e (diff) | |
download | django-11a9017179812198a12a2fc19610262a549aa46e.tar.gz |
Fixed #29966 -- Added tests for BaseHandler's "The view didn't return an HttpResponse object" error.
Diffstat (limited to 'tests/handlers')
-rw-r--r-- | tests/handlers/tests.py | 10 | ||||
-rw-r--r-- | tests/handlers/urls.py | 3 | ||||
-rw-r--r-- | tests/handlers/views.py | 9 |
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py index 175a892618..2edca592ab 100644 --- a/tests/handlers/tests.py +++ b/tests/handlers/tests.py @@ -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): diff --git a/tests/handlers/urls.py b/tests/handlers/urls.py index 1a22859093..015527ac51 100644 --- a/tests/handlers/urls.py +++ b/tests/handlers/urls.py @@ -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), diff --git a/tests/handlers/views.py b/tests/handlers/views.py index 8005cc605f..872fd52676 100644 --- a/tests/handlers/views.py +++ b/tests/handlers/views.py @@ -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"]) |