Ticket #12226: 12226_r13760.diff

File 12226_r13760.diff, 3.4 KB (added by carljm, 5 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 
    44import os
    55import re
    66import mimetypes
     7import warnings
    78try:
    89    from cStringIO import StringIO
    910except ImportError:
    def store_rendered_templates(store, signal, sender, template, context, **kwargs) 
    9394    """
    9495    Stores templates and contexts that are rendered.
    9596    """
    96     store.setdefault('template', []).append(template)
     97    store.setdefault('templates', []).append(template)
    9798    store.setdefault('context', ContextList()).append(context)
    9899
    99100def encode_multipart(boundary, data):
    class Client(object): 
    260261            response.request = request
    261262
    262263            # 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)
    273283
    274284            # Update persistent cookie data.
    275285            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): 
    445445        if msg_prefix:
    446446            msg_prefix += ": "
    447447
    448         template_names = [t.name for t in to_list(response.template)]
     448        template_names = [t.name for t in response.templates]
    449449        if not template_names:
    450450            self.fail(msg_prefix + "No templates used to render the response")
    451451        self.failUnless(template_name in template_names,
    class TransactionTestCase(unittest.TestCase): 
    461461        if msg_prefix:
    462462            msg_prefix += ": "
    463463
    464         template_names = [t.name for t in to_list(response.template)]
     464        template_names = [t.name for t in response.templates]
    465465        self.failIf(template_name in template_names,
    466466            msg_prefix + "Template '%s' was used unexpectedly in rendering"
    467467            " the response" % template_name)
Back to Top