Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18356 -- Gave the test client signals.template_rendered call a…

… unique dispatch_uid

This prevents the test client context from being lost when the client
is used in a nested fashion.
  • Loading branch information...
commit 0cac4fbf699bb6a3de5f4a48c6e047a4dc6c2df7 1 parent 453915b
@bmihelac bmihelac authored timgraham committed
View
1  AUTHORS
@@ -418,6 +418,7 @@ answer newbie questions, and generally made Django that much better:
Christian Metts
michal@plovarna.cz
Justin Michalicek <jmichalicek@gmail.com>
+ Bojan Mihelac <bmihelac@mihelac.org>
Slawek Mikula <slawek dot mikula at gmail dot com>
Katie Miller <katie@sub50.com>
Shawn Milochik <shawn@milochik.com>
View
5 django/test/client.py
@@ -406,7 +406,8 @@ def request(self, **request):
# callback function.
data = {}
on_template_render = curry(store_rendered_templates, data)
- signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")
+ signal_uid = "template-render-%s" % id(request)
+ signals.template_rendered.connect(on_template_render, dispatch_uid=signal_uid)
# Capture exceptions created by the handler.
got_request_exception.connect(self.store_exc_info, dispatch_uid="request-exception")
try:
@@ -452,7 +453,7 @@ def request(self, **request):
return response
finally:
- signals.template_rendered.disconnect(dispatch_uid="template-render")
+ signals.template_rendered.disconnect(dispatch_uid=signal_uid)
got_request_exception.disconnect(dispatch_uid="request-exception")
def get(self, path, data={}, follow=False, **extra):
View
8 tests/test_client_regress/tests.py
@@ -925,6 +925,14 @@ def test_15368(self):
finally:
django.template.context._standard_context_processors = None
+ def test_nested_requests(self):
+ """
+ response.context is not lost when view call another view.
+ """
+ response = self.client.get("/test_client_regress/nested_view/")
+ self.assertEqual(response.context.__class__, Context)
+ self.assertEqual(response.context['nested'], 'yes')
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class SessionTests(TestCase):
View
1  tests/test_client_regress/urls.py
@@ -11,6 +11,7 @@
(r'^request_data/$', views.request_data),
(r'^request_data_extended/$', views.request_data, {'template':'extended.html', 'data':'bacon'}),
url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'),
+ url(r'^nested_view/$', views.nested_view, name='nested_view'),
(r'^login_protected_redirect_view/$', views.login_protected_redirect_view),
(r'^redirects/$', RedirectView.as_view(url='/test_client_regress/redirects/further/')),
(r'^redirects/further/$', RedirectView.as_view(url='/test_client_regress/redirects/further/more/')),
View
13 tests/test_client_regress/views.py
@@ -5,8 +5,10 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.core.serializers.json import DjangoJSONEncoder
-from django.test.client import CONTENT_TYPE_RE
from django.template import RequestContext
+from django.test import Client
+from django.test.client import CONTENT_TYPE_RE
+from django.test.utils import setup_test_environment
class CustomTestException(Exception):
@@ -52,6 +54,15 @@ def view_with_argument(request, name):
else:
return HttpResponse('Howdy, %s' % name)
+def nested_view(request):
+ """
+ A view that uses test client to call another view.
+ """
+ setup_test_environment()
+ c = Client()
+ c.get("/test_client_regress/no_template_view")
+ return render_to_response('base.html', {'nested':'yes'})
+
def login_protected_redirect_view(request):
"A view that redirects all requests to the GET view"
return HttpResponseRedirect('/test_client_regress/get_view/')
Please sign in to comment.
Something went wrong with that request. Please try again.