Ticket #12226: 12226_r13760.diff
File 12226_r13760.diff, 3.4 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)