From 6eb7cd1af49950f9128b7867a8ce886223b47d4f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 6 Aug 2010 16:34:34 +0000 Subject: [PATCH] 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 --- django/test/utils.py | 6 ++++++ tests/regressiontests/test_client_regress/models.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/django/test/utils.py b/django/test/utils.py index b6ab39901b..404d130297 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -19,6 +19,12 @@ class ContextList(list): else: 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): """ diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 6da7ae4445..a740237321 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -619,6 +619,7 @@ class ContextTests(TestCase): "Context variables can be retrieved from a single context" response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'}) self.assertEqual(response.context.__class__, Context) + self.assertTrue('get-foo' in response.context) self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['request-foo'], 'whiz') 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'}) self.assertEqual(response.context.__class__, ContextList) self.assertEqual(len(response.context), 2) + self.assertTrue('get-foo' in response.context) self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['data'], 'bacon')