Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 6eb7cd1af49950f9128b7867a8ce886223b47d4f 1 parent c4b6edf
Russell Keith-Magee authored
6  django/test/utils.py
@@ -19,6 +19,12 @@ def __getitem__(self, key):
19 19
         else:
20 20
             return super(ContextList, self).__getitem__(key)
21 21
 
  22
+    def __contains__(self, key):
  23
+        try:
  24
+            value = self[key]
  25
+        except KeyError:
  26
+            return False
  27
+        return True
22 28
 
23 29
 def instrumented_test_render(self, context):
24 30
     """
2  tests/regressiontests/test_client_regress/models.py
@@ -619,6 +619,7 @@ def test_single_context(self):
619 619
         "Context variables can be retrieved from a single context"
620 620
         response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'})
621 621
         self.assertEqual(response.context.__class__, Context)
  622
+        self.assertTrue('get-foo' in response.context)
622 623
         self.assertEqual(response.context['get-foo'], 'whiz')
623 624
         self.assertEqual(response.context['request-foo'], 'whiz')
624 625
         self.assertEqual(response.context['data'], 'sausage')
@@ -634,6 +635,7 @@ def test_inherited_context(self):
634 635
         response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
635 636
         self.assertEqual(response.context.__class__, ContextList)
636 637
         self.assertEqual(len(response.context), 2)
  638
+        self.assertTrue('get-foo' in response.context)
637 639
         self.assertEqual(response.context['get-foo'], 'whiz')
638 640
         self.assertEqual(response.context['request-foo'], 'whiz')
639 641
         self.assertEqual(response.context['data'], 'bacon')

0 notes on commit 6eb7cd1

Please sign in to comment.
Something went wrong with that request. Please try again.