diff options
author | Russell Keith-Magee <russell@keith-magee.com> | 2009-03-18 10:46:55 +0000 |
---|---|---|
committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-03-18 10:46:55 +0000 |
commit | ee2f04d79e5bca55637b9bb3301618738a4e342a (patch) | |
tree | 91e94bc284c1cb44ce131b8acc972e3585b2b110 /django/test/utils.py | |
parent | 61a2708c4108939795c70cf124d5696275d6c255 (diff) | |
download | django-ee2f04d79e5bca55637b9bb3301618738a4e342a.tar.gz |
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
Diffstat (limited to 'django/test/utils.py')
-rw-r--r-- | django/test/utils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/django/test/utils.py b/django/test/utils.py index 29babec3ff..d34dd33d15 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -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 |