diff --git a/django/test/client.py b/django/test/client.py
index 348bfa7..5fc5877 100644
a
|
b
|
from urlparse import urlparse, urlunparse, urlsplit
|
3 | 3 | import sys |
4 | 4 | import os |
5 | 5 | import re |
| 6 | from copy import deepcopy |
6 | 7 | try: |
7 | 8 | from cStringIO import StringIO |
8 | 9 | except ImportError: |
… |
… |
def store_rendered_templates(store, signal, sender, template, context, **kwargs)
|
84 | 85 | Stores templates and contexts that are rendered. |
85 | 86 | """ |
86 | 87 | store.setdefault('template', []).append(template) |
87 | | store.setdefault('context', ContextList()).append(context) |
| 88 | store.setdefault('context', ContextList()).append(deepcopy(context)) |
88 | 89 | |
89 | 90 | def encode_multipart(boundary, data): |
90 | 91 | """ |
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index be2cb8f..973bf75 100644
a
|
b
|
class ContextTests(TestCase):
|
498 | 498 | self.assertEqual(response.context['request-foo'], 'whiz') |
499 | 499 | self.assertEqual(response.context['data'], 'bacon') |
500 | 500 | |
| 501 | def test_subcontext(self): |
| 502 | "Context variables can be retrieved from subcontexts" |
| 503 | response = self.client.get('/test_client_regress/subcontext/', data={'supervar': 1, 'value_for_subvar': 2}) |
| 504 | self.assertEqual(len(response.context), 2) |
| 505 | self.assertEqual(response.context['supervar'], u'1') |
| 506 | self.assertEqual(response.context['subvar'], u'2') |
| 507 | |
| 508 | def test_subcontext_direct(self): |
| 509 | "Context variables retrieved from subcontexts can be accessed separately" |
| 510 | response = self.client.get('/test_client_regress/subcontext/', data={'supervar': 1, 'value_for_subvar': 2}) |
| 511 | |
| 512 | # context for the supertemplate: subcontext not yet set |
| 513 | self.assertEqual(response.context[0]['supervar'], u'1') |
| 514 | self.assertFalse('subvar' in response.context[0]) |
| 515 | |
| 516 | # context for the subtemplate: subcontext has been set |
| 517 | self.assertEqual(response.context[1]['supervar'], u'1') |
| 518 | self.assertEqual(response.context[1]['subvar'], u'2') |
| 519 | |
501 | 520 | class SessionTests(TestCase): |
502 | 521 | fixtures = ['testdata.json'] |
503 | 522 | |
diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py
index 99eb7b7..f1db23a 100644
a
|
b
|
urlpatterns = patterns('',
|
24 | 24 | (r'^request_methods/$', views.request_methods_view), |
25 | 25 | (r'^check_unicode/$', views.return_unicode), |
26 | 26 | (r'^parse_unicode_json/$', views.return_json_file), |
| 27 | (r'^subcontext/$', views.view_with_subcontext), |
27 | 28 | ) |
diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
index 5ba7cc3..0e0c3aa 100644
a
|
b
|
def return_json_file(request):
|
86 | 86 | mimetype='application/json; charset=' + charset) |
87 | 87 | response['Content-Disposition'] = 'attachment; filename=testfile.json' |
88 | 88 | return response |
| 89 | |
| 90 | def view_with_subcontext(request): |
| 91 | """A view that augments the context when including a sub-template |
| 92 | |
| 93 | The purpose of this view is to check that the test client |
| 94 | correctly catches context variables from sub-contexts. This |
| 95 | happens when a sub-template is rendered with a context modified or |
| 96 | created by a template tag. |
| 97 | """ |
| 98 | return render_to_response("testclient/super.html", |
| 99 | {'supervar': request.GET['supervar'], |
| 100 | 'value_for_subvar': request.GET['value_for_subvar']}) |
diff --git a/tests/templates/testclient/sub.html b/tests/templates/testclient/sub.html
new file mode 100644
index 0000000..bb4cad6
diff --git a/tests/templates/testclient/super.html b/tests/templates/testclient/super.html
new file mode 100644
index 0000000..998fb0c
-
|
+
|
|
| 1 | Value of supervar: {{ supervar }} |
| 2 | Value of subvar: {% with value_for_subvar as subvar %}{% include "testclient/sub.html" %}{% endwith %} |