diff options
| author | pscottdevos <scott.devos@sykes.com> | 2015-08-07 14:28:54 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-11 10:01:24 -0400 |
| commit | 7fa1dd8a80795d7573fe650014c5d23af7557bc7 (patch) | |
| tree | f3278cad054f28203a614854c2787e1debe10955 /tests | |
| parent | 56ed80ac2a7dac6dc26754f7fe95941e8a6f124e (diff) | |
Fixed #25163 -- Fixed exception handling in nested test client requests.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_client/tests.py | 8 | ||||
| -rw-r--r-- | tests/test_client/urls.py | 1 | ||||
| -rw-r--r-- | tests/test_client/views.py | 11 |
3 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py index ae70f5c494..042633ad54 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -640,6 +640,14 @@ class ClientTest(TestCase): self.assertEqual(mail.outbox[1].to[0], 'second@example.com') self.assertEqual(mail.outbox[1].to[1], 'third@example.com') + def test_exception_following_nested_client_request(self): + """ + A nested test client request shouldn't clobber exception signals from + the outer client request. + """ + with self.assertRaisesMessage(Exception, 'exception message'): + self.client.get('/nesting_exception_view/') + @override_settings( MIDDLEWARE_CLASSES=['django.middleware.csrf.CsrfViewMiddleware'], diff --git a/tests/test_client/urls.py b/tests/test_client/urls.py index 1b7530db1c..f605448b5b 100644 --- a/tests/test_client/urls.py +++ b/tests/test_client/urls.py @@ -31,6 +31,7 @@ urlpatterns = [ url(r'^broken_view/$', views.broken_view), url(r'^mail_sending_view/$', views.mail_sending_view), url(r'^mass_mail_sending_view/$', views.mass_mail_sending_view), + url(r'^nesting_exception_view/$', views.nesting_exception_view), url(r'^django_project_redirect/$', views.django_project_redirect), url(r'^accounts/login/$', auth_views.login, {'template_name': 'login.html'}), diff --git a/tests/test_client/views.py b/tests/test_client/views.py index f26d474612..070e6305c2 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -11,6 +11,7 @@ from django.http import ( ) from django.shortcuts import render_to_response from django.template import Context, Template +from django.test import Client from django.utils.decorators import method_decorator from django.utils.six.moves.urllib.parse import urlencode @@ -309,5 +310,15 @@ def mass_mail_sending_view(request): return HttpResponse("Mail sent") +def nesting_exception_view(request): + """ + A view that uses a nested client to call another view and then raises an + exception. + """ + client = Client() + client.get('/get_view/') + raise Exception('exception message') + + def django_project_redirect(request): return HttpResponseRedirect('https://www.djangoproject.com/') |
