From ee2f04d79e5bca55637b9bb3301618738a4e342a Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 18 Mar 2009 10:46:55 +0000 Subject: 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 --- django/test/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'django/test/utils.py') 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 -- cgit v1.3