Fixed #13092 -- Added support for the "in" operator when dealing with context lists. Thanks to clelland for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13510 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-08-06 16:34:34 +00:00
parent c4b6edf3b8
commit 6eb7cd1af4
2 changed files with 8 additions and 0 deletions

View File

@ -19,6 +19,12 @@ class ContextList(list):
else: else:
return super(ContextList, self).__getitem__(key) return super(ContextList, self).__getitem__(key)
def __contains__(self, key):
try:
value = self[key]
except KeyError:
return False
return True
def instrumented_test_render(self, context): def instrumented_test_render(self, context):
""" """

View File

@ -619,6 +619,7 @@ class ContextTests(TestCase):
"Context variables can be retrieved from a single context" "Context variables can be retrieved from a single context"
response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'}) response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'})
self.assertEqual(response.context.__class__, Context) self.assertEqual(response.context.__class__, Context)
self.assertTrue('get-foo' in response.context)
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['data'], 'sausage') self.assertEqual(response.context['data'], 'sausage')
@ -634,6 +635,7 @@ class ContextTests(TestCase):
response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'}) response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
self.assertEqual(response.context.__class__, ContextList) self.assertEqual(response.context.__class__, ContextList)
self.assertEqual(len(response.context), 2) self.assertEqual(len(response.context), 2)
self.assertTrue('get-foo' in response.context)
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['data'], 'bacon') self.assertEqual(response.context['data'], 'bacon')