diff options
| author | Bojan Mihelac <bmihelac@mihelac.org> | 2013-02-04 16:50:15 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-08-09 12:22:42 -0400 |
| commit | 0cac4fbf699bb6a3de5f4a48c6e047a4dc6c2df7 (patch) | |
| tree | 74724e0074079f25fed1b292d5dbeaaecc482ae5 /tests | |
| parent | 453915bb1272c9a9189a741e6a9b9246edfcbd03 (diff) | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_client_regress/tests.py | 8 | ||||
| -rw-r--r-- | tests/test_client_regress/urls.py | 1 | ||||
| -rw-r--r-- | tests/test_client_regress/views.py | 13 |
3 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index 67e66fa52d..857d6d83c0 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -925,6 +925,14 @@ class ContextTests(TestCase): 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): diff --git a/tests/test_client_regress/urls.py b/tests/test_client_regress/urls.py index 6a0b330e02..1bde10315d 100644 --- a/tests/test_client_regress/urls.py +++ b/tests/test_client_regress/urls.py @@ -11,6 +11,7 @@ urlpatterns = patterns('', (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/')), diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py index 71e5b526e5..d7c54cf2f7 100644 --- a/tests/test_client_regress/views.py +++ b/tests/test_client_regress/views.py @@ -5,8 +5,10 @@ from django.contrib.auth.decorators import login_required 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/') |
