1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #10482 -- Unified access to response.context when inspecting responses from the test client. Thanks to James Bennett for the design, and Julien Phalip for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2009-03-18 10:46:55 +00:00
parent 61a2708c41
commit ee2f04d79e
7 changed files with 58 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ from django.utils.encoding import smart_str
from django.utils.http import urlencode
from django.utils.itercompat import is_iterable
from django.db import transaction, close_connection
from django.test.utils import ContextList
BOUNDARY = 'BoUnDaRyStRiNg'
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
@@ -80,8 +81,8 @@ def store_rendered_templates(store, signal, sender, template, context, **kwargs)
"""
Stores templates and contexts that are rendered.
"""
store.setdefault('template',[]).append(template)
store.setdefault('context',[]).append(context)
store.setdefault('template', []).append(template)
store.setdefault('context', ContextList()).append(context)
def encode_multipart(boundary, data):
"""

View File

@@ -6,6 +6,20 @@ from django.test import signals
from django.template import Template
from django.utils.translation import deactivate
class ContextList(list):
"""A wrapper that provides direct key access to context items contained
in a list of context objects.
"""
def __getitem__(self, key):
if isinstance(key, basestring):
for subcontext in self:
if key in subcontext:
return subcontext[key]
raise KeyError
else:
return super(ContextList, self).__getitem__(key)
def instrumented_test_render(self, context):
"""
An instrumented Template render method, providing a signal