Code

Ticket #18356: 18356-test-client-context-lost-for-nested-views.diff

File 18356-test-client-context-lost-for-nested-views.diff, 3.4 KB (added by bmihelac, 2 years ago)
Line 
1From 720bd81aad14c6dae9fb952686b55bae236f7769 Mon Sep 17 00:00:00 2001
2From: Bojan Mihelac <bmihelac@mihelac.org>
3Date: Sun, 20 May 2012 17:51:17 +0200
4Subject: [PATCH] Add failing tests for #18356
5
6---
7 .../regressiontests/test_client_regress/models.py  |    8 ++++++++
8 tests/regressiontests/test_client_regress/urls.py  |    1 +
9 tests/regressiontests/test_client_regress/views.py |   12 ++++++++++++
10 3 files changed, 21 insertions(+), 0 deletions(-)
11
12diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
13index 4f057b9..e307feb 100644
14--- a/tests/regressiontests/test_client_regress/models.py
15+++ b/tests/regressiontests/test_client_regress/models.py
16@@ -711,6 +711,14 @@ class ContextTests(TestCase):
17         finally:
18             django.template.context._standard_context_processors = None
19 
20+    def test_nested_requests(self):
21+        """
22+        response.context is not lost when view call another view.
23+        """
24+        response = self.client.get("/test_client_regress/nested_view/")
25+        self.assertEqual(response.context.__class__, Context)
26+        self.assertEqual(response.context['nested'], 'yes')
27+
28 
29 @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
30 class SessionTests(TestCase):
31diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py
32index d869c23..193d5f4 100644
33--- a/tests/regressiontests/test_client_regress/urls.py
34+++ b/tests/regressiontests/test_client_regress/urls.py
35@@ -13,6 +13,7 @@ urlpatterns = patterns('',
36     (r'^request_data/$', views.request_data),
37     (r'^request_data_extended/$', views.request_data, {'template':'extended.html', 'data':'bacon'}),
38     url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'),
39+    url(r'^nested_view/$', views.nested_view, name='nested_view'),
40     (r'^login_protected_redirect_view/$', views.login_protected_redirect_view),
41     (r'^redirects/$', RedirectView.as_view(url='/test_client_regress/redirects/further/')),
42     (r'^redirects/further/$', RedirectView.as_view(url='/test_client_regress/redirects/further/more/')),
43diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
44index ab625a9..8b71c53 100644
45--- a/tests/regressiontests/test_client_regress/views.py
46+++ b/tests/regressiontests/test_client_regress/views.py
47@@ -9,6 +9,9 @@ from django.utils.encoding import smart_str
48 from django.core.serializers.json import DjangoJSONEncoder
49 from django.test.client import CONTENT_TYPE_RE
50 from django.template import RequestContext
51+from django.test import Client
52+from django.test.utils import setup_test_environment
53+
54 
55 def no_template_view(request):
56     "A simple view that expects a GET request, and returns a rendered template"
57@@ -50,6 +53,15 @@ def view_with_argument(request, name):
58     else:
59         return HttpResponse('Howdy, %s' % name)
60 
61+def nested_view(request):
62+    """
63+    A view that uses test client to call another view.
64+    """
65+    setup_test_environment()
66+    c = Client()
67+    c.get("/test_client_regress/no_template_view")
68+    return render_to_response('base.html', {'nested':'yes'})
69+
70 def login_protected_redirect_view(request):
71     "A view that redirects all requests to the GET view"
72     return HttpResponseRedirect('/test_client_regress/get_view/')
73--
741.7.3.1
75