Ticket #10482: 10482.consistent_response_context.diff
File 10482.consistent_response_context.diff, 5.8 KB (added by , 16 years ago) |
---|
-
django/django/test/client.py
20 20 from django.utils.http import urlencode 21 21 from django.utils.itercompat import is_iterable 22 22 from django.db import transaction, close_connection 23 from django.test.utils import ContextList 23 24 24 25 BOUNDARY = 'BoUnDaRyStRiNg' 25 26 MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY … … 81 82 Stores templates and contexts that are rendered. 82 83 """ 83 84 store.setdefault('template',[]).append(template) 84 store.setdefault('context', []).append(context)85 store.setdefault('context',ContextList()).append(context) 85 86 86 87 def encode_multipart(boundary, data): 87 88 """ -
django/django/test/utils.py
6 6 from django.template import Template 7 7 from django.utils.translation import deactivate 8 8 9 class ContextList(list): 10 11 def __getitem__(self, key): 12 if type(key) == str: 13 for subcontext in self: 14 if key in subcontext: 15 return subcontext[key] 16 raise KeyError 17 else: 18 return super(ContextList, self).__getitem__(key) 19 20 9 21 def instrumented_test_render(self, context): 10 22 """ 11 23 An instrumented Template render method, providing a signal -
django/docs/topics/testing.txt
710 710 produced the response content. 711 711 712 712 If the rendered page used multiple templates, then ``context`` will be a 713 list of ``Context`` objects, in the order in which they were rendered. 713 list of ``Context`` objects, in the order in which they were rendered. Regardless 714 of the number of templates used, context variables can be directly accessed from this 715 attribute without looking in each ``Context`` object. 714 716 715 717 .. attribute:: request 716 718 -
django/tests/regressiontests/test_client_regress/context_templates/extended.html
1 {% extends "base.html" %} 2 {% block title %}Extended template{% endblock %} 3 {% block content %} 4 This is just a template extending the base. 5 {% endblock %} 6 No newline at end of file -
django/tests/regressiontests/test_client_regress/models.py
455 455 url = reverse('arg_view', args=['somename']) 456 456 self.assertEquals(url, '/test_client_regress/arg_view/somename/') 457 457 458 class ContextTests(TestCase): 459 fixtures = ['testdata'] 460 461 def setUp(self): 462 self.old_templates = settings.TEMPLATE_DIRS 463 settings.TEMPLATE_DIRS += (os.path.join(os.path.dirname(__file__), 'context_templates'),) 464 465 def tearDown(self): 466 settings.TEMPLATE_DIRS = self.old_templates 467 468 def test_context(self): 469 # Without template inheritance 470 response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'}) 471 self.assertEqual(response.context['get-foo'], 'whiz') 472 self.assertEqual(response.context['request-foo'], 'whiz') 473 474 # With template inheritance 475 response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'}) 476 self.assertEqual(response.context['get-foo'], 'whiz') 477 self.assertEqual(response.context['request-foo'], 'whiz') 478 458 479 class SessionTests(TestCase): 459 480 fixtures = ['testdata.json'] 460 481 -
django/tests/regressiontests/test_client_regress/urls.py
7 7 (r'^staff_only/$', views.staff_only_view), 8 8 (r'^get_view/$', views.get_view), 9 9 (r'^request_data/$', views.request_data), 10 (r'^request_data_extended/$', views.request_data, {'template':'extended.html'}), 10 11 url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'), 11 12 (r'^login_protected_redirect_view/$', views.login_protected_redirect_view), 12 13 (r'^redirects/$', redirect_to, {'url': '/test_client_regress/redirects/further/'}), -
django/tests/regressiontests/test_client_regress/views.py
19 19 return HttpResponse("Hello world") 20 20 get_view = login_required(get_view) 21 21 22 def request_data(request ):22 def request_data(request, template='base.html'): 23 23 "A simple view that returns the request data in the context" 24 return render_to_response( 'base.html', {24 return render_to_response(template, { 25 25 'get-foo':request.GET.get('foo',None), 26 26 'get-bar':request.GET.get('bar',None), 27 27 'post-foo':request.POST.get('foo',None),