summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Beaven <smileychris@gmail.com>2011-02-21 10:13:11 +0000
committerChris Beaven <smileychris@gmail.com>2011-02-21 10:13:11 +0000
commit39b8a1f7ed49de3a1a32bd842de6e2b92a4bb8b6 (patch)
tree82c6d06665f057dba365660168f3adae2cb456db
parent3db9383dafdbeb6d50027c1ff5dda14babd23420 (diff)
[1.2.X] Fix broken tests due to changes in r15591 by updating the test store_rendered_templates signal handler.
Backport of r15600 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15601 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/context.py25
-rw-r--r--django/test/client.py8
2 files changed, 31 insertions, 2 deletions
diff --git a/django/template/context.py b/django/template/context.py
index 323c1446b2..4aa454edce 100644
--- a/django/template/context.py
+++ b/django/template/context.py
@@ -1,5 +1,7 @@
+from copy import copy
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
+from django.http import HttpRequest
# Cache of actual callables.
_standard_context_processors = None
@@ -17,6 +19,11 @@ class BaseContext(object):
dict_ = dict_ or {}
self.dicts = [dict_]
+ def __copy__(self):
+ duplicate = self._new()
+ duplicate.dicts = [dict_ for dict_ in self.dicts]
+ return duplicate
+
def __repr__(self):
return repr(self.dicts)
@@ -24,6 +31,9 @@ class BaseContext(object):
for d in reversed(self.dicts):
yield d
+ def _new(self):
+ return self.__class__()
+
def push(self):
d = {}
self.dicts.append(d)
@@ -72,6 +82,16 @@ class Context(BaseContext):
self.render_context = RenderContext()
super(Context, self).__init__(dict_)
+ def __copy__(self):
+ duplicate = super(Context, self).__copy__()
+ duplicate.render_context = copy(self.render_context)
+ return duplicate
+
+ def _new(self):
+ return self.__class__(autoescape=self.autoescape,
+ current_app=self.current_app,
+ use_l10n=self.use_l10n)
+
def update(self, other_dict):
"Like dict.update(). Pushes an entire dictionary's keys and values onto the context."
if not hasattr(other_dict, '__getitem__'):
@@ -147,3 +167,8 @@ class RequestContext(Context):
processors = tuple(processors)
for processor in get_standard_processors() + processors:
self.update(processor(request))
+
+ def _new(self):
+ return self.__class__(request=HttpRequest(),
+ current_app=self.current_app,
+ use_l10n=self.use_l10n)
diff --git a/django/test/client.py b/django/test/client.py
index 2a7892631d..7047c5e8fa 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -4,6 +4,7 @@ import sys
import os
import re
import mimetypes
+from copy import copy
try:
from cStringIO import StringIO
except ImportError:
@@ -92,9 +93,12 @@ class ClientHandler(BaseHandler):
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
"""
Stores templates and contexts that are rendered.
+
+ The context is copied so that it is an accurate representation at the time
+ of rendering.
"""
- store.setdefault('template', []).append(template)
- store.setdefault('context', ContextList()).append(context)
+ store.setdefault('templates', []).append(template)
+ store.setdefault('context', ContextList()).append(copy(context))
def encode_multipart(boundary, data):
"""