Ticket #12226: 12226_r13760.2.diff
File 12226_r13760.2.diff, 7.3 KB (added by , 14 years ago) |
---|
-
django/test/client.py
diff --git a/django/test/client.py b/django/test/client.py index 08e3ff6..0588088 100644
a b import sys 4 4 import os 5 5 import re 6 6 import mimetypes 7 import warnings 7 8 try: 8 9 from cStringIO import StringIO 9 10 except ImportError: … … def store_rendered_templates(store, signal, sender, template, context, **kwargs) 93 94 """ 94 95 Stores templates and contexts that are rendered. 95 96 """ 96 store.setdefault('template ', []).append(template)97 store.setdefault('templates', []).append(template) 97 98 store.setdefault('context', ContextList()).append(context) 98 99 99 100 def encode_multipart(boundary, data): … … class Client(object): 260 261 response.request = request 261 262 262 263 # Add any rendered template detail to the response. 263 # If there was only one template rendered (the most likely case), 264 # flatten the list to a single element. 265 for detail in ('template', 'context'): 266 if data.get(detail): 267 if len(data[detail]) == 1: 268 setattr(response, detail, data[detail][0]); 269 else: 270 setattr(response, detail, data[detail]) 271 else: 272 setattr(response, detail, None) 264 response.templates = data.get("templates", []) 265 response.context = data.get("context") 266 267 # Flatten a single context. Not really necessary anymore thanks to 268 # the __getattr__ flattening in ContextList, but has some edge-case 269 # backwards-compatibility implications. 270 if response.context and len(response.context) == 1: 271 response.context = response.context[0] 272 273 # Provide a backwards-compatible (but pending deprecation) response.template 274 def _get_template(self): 275 warnings.warn("response.template is deprecated; use response.templates instead (which is always a list)", 276 PendingDeprecationWarning) 277 if not self.templates: 278 return None 279 elif len(self.templates) == 1: 280 return self.templates[0] 281 return self.templates 282 response.__class__.template = property(_get_template) 273 283 274 284 # Update persistent cookie data. 275 285 if response.cookies: -
django/test/testcases.py
diff --git a/django/test/testcases.py b/django/test/testcases.py index 10bd6c6..1a34fd9 100644
a b class TransactionTestCase(unittest.TestCase): 445 445 if msg_prefix: 446 446 msg_prefix += ": " 447 447 448 template_names = [t.name for t in to_list(response.template)]448 template_names = [t.name for t in response.templates] 449 449 if not template_names: 450 450 self.fail(msg_prefix + "No templates used to render the response") 451 451 self.failUnless(template_name in template_names, … … class TransactionTestCase(unittest.TestCase): 461 461 if msg_prefix: 462 462 msg_prefix += ": " 463 463 464 template_names = [t.name for t in to_list(response.template)]464 template_names = [t.name for t in response.templates] 465 465 self.failIf(template_name in template_names, 466 466 msg_prefix + "Template '%s' was used unexpectedly in rendering" 467 467 " the response" % template_name) -
tests/modeltests/test_client/models.py
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 3052008..5cd61bf 100644
a b class ClientTest(TestCase): 37 37 # Check some response details 38 38 self.assertContains(response, 'This is a test') 39 39 self.assertEqual(response.context['var'], u'\xf2') 40 self.assertEqual(response.template .name, 'GET Template')40 self.assertEqual(response.templates[0].name, 'GET Template') 41 41 42 42 def test_get_post_view(self): 43 43 "GET a view that normally expects POSTs" … … class ClientTest(TestCase): 45 45 46 46 # Check some response details 47 47 self.assertEqual(response.status_code, 200) 48 self.assertEqual(response.template .name, 'Empty GET Template')48 self.assertEqual(response.templates[0].name, 'Empty GET Template') 49 49 self.assertTemplateUsed(response, 'Empty GET Template') 50 50 self.assertTemplateNotUsed(response, 'Empty POST Template') 51 51 … … class ClientTest(TestCase): 55 55 56 56 # Check some response details 57 57 self.assertEqual(response.status_code, 200) 58 self.assertEqual(response.template .name, 'Empty POST Template')58 self.assertEqual(response.templates[0].name, 'Empty POST Template') 59 59 self.assertTemplateNotUsed(response, 'Empty GET Template') 60 60 self.assertTemplateUsed(response, 'Empty POST Template') 61 61 … … class ClientTest(TestCase): 69 69 # Check some response details 70 70 self.assertEqual(response.status_code, 200) 71 71 self.assertEqual(response.context['data'], '37') 72 self.assertEqual(response.template .name, 'POST Template')72 self.assertEqual(response.templates[0].name, 'POST Template') 73 73 self.failUnless('Data received' in response.content) 74 74 75 75 def test_response_headers(self): … … class ClientTest(TestCase): 84 84 response = self.client.post("/test_client/raw_post_view/", test_doc, 85 85 content_type="text/xml") 86 86 self.assertEqual(response.status_code, 200) 87 self.assertEqual(response.template .name, "Book template")87 self.assertEqual(response.templates[0].name, "Book template") 88 88 self.assertEqual(response.content, "Blink - Malcolm Gladwell") 89 89 90 90 def test_redirect(self): -
tests/regressiontests/test_client_regress/models.py
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 22b59e5..20ed3af 100644
a b from django.test import Client, TestCase 9 9 from django.test.utils import ContextList 10 10 from django.core.urlresolvers import reverse 11 11 from django.core.exceptions import SuspiciousOperation 12 from django.template import TemplateDoesNotExist, TemplateSyntaxError, Context 12 from django.template import TemplateDoesNotExist, TemplateSyntaxError, Context, Template 13 13 from django.template import loader 14 14 from django.test.client import encode_file 15 15 … … class RequestHeadersTest(TestCase): 861 861 self.assertEquals(response.content, "HTTP_X_ARG_CHECK: Testing 123") 862 862 self.assertRedirects(response, '/test_client_regress/check_headers/', 863 863 status_code=301, target_status_code=200) 864 865 class ResponseTemplateDeprecationTests(TestCase): 866 """ 867 Response.template still works backwards-compatibly, but with pending deprecation warning. Refs #12226. 868 869 """ 870 def test_response_template_data(self): 871 response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'}) 872 self.assertEqual(response.template.__class__, Template) 873 self.assertEqual(response.template.name, 'base.html') 874 875 def test_response_no_template(self): 876 response = self.client.get("/test_client_regress/request_methods/") 877 self.assertEqual(response.template, None) 878