Ticket #13092: test_key_in_context_1.diff

File test_key_in_context_1.diff, 1.7 KB (added by Ian Clelland, 15 years ago)

Patch to allow tests like 'key in contextlist'

  • django/test/utils.py

     
    1919        else:
    2020            return super(ContextList, self).__getitem__(key)
    2121
     22    def __contains__(self, key):
     23        try:
     24            value = self[key]
     25        except KeyError:
     26            return False
     27        return True
    2228
    2329def instrumented_test_render(self, context):
    2430    """
  • tests/regressiontests/test_client_regress/models.py

     
    598598        "Context variables can be retrieved from a single context"
    599599        response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'})
    600600        self.assertEqual(response.context.__class__, Context)
     601        self.assertTrue('get-foo' in response.context)
    601602        self.assertEqual(response.context['get-foo'], 'whiz')
    602603        self.assertEqual(response.context['request-foo'], 'whiz')
    603604        self.assertEqual(response.context['data'], 'sausage')
     
    613614        response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
    614615        self.assertEqual(response.context.__class__, ContextList)
    615616        self.assertEqual(len(response.context), 2)
     617        self.assertTrue('get-foo' in response.context)
    616618        self.assertEqual(response.context['get-foo'], 'whiz')
    617619        self.assertEqual(response.context['request-foo'], 'whiz')
    618620        self.assertEqual(response.context['data'], 'bacon')
Back to Top