Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12659 -- Return a more meaningful KeyError message when Contex…

…tList lookups fail. Thanks to rodriguealcazar for the suggestion.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12274 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f114fbecc2a486df7fc65f7de1b635520ef1d5ba 1 parent 7ca9d93
Russell Keith-Magee authored January 22, 2010
2  django/test/utils.py
@@ -15,7 +15,7 @@ def __getitem__(self, key):
15 15
             for subcontext in self:
16 16
                 if key in subcontext:
17 17
                     return subcontext[key]
18  
-            raise KeyError
  18
+            raise KeyError(key)
19 19
         else:
20 20
             return super(ContextList, self).__getitem__(key)
21 21
 
13  tests/regressiontests/test_client_regress/models.py
@@ -602,6 +602,12 @@ def test_single_context(self):
602 602
         self.assertEqual(response.context['request-foo'], 'whiz')
603 603
         self.assertEqual(response.context['data'], 'sausage')
604 604
 
  605
+        try:
  606
+            response.context['does-not-exist']
  607
+            self.fail('Should not be able to retrieve non-existent key')
  608
+        except KeyError, e:
  609
+            self.assertEquals(e.message, 'does-not-exist')
  610
+
605 611
     def test_inherited_context(self):
606 612
         "Context variables can be retrieved from a list of contexts"
607 613
         response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
@@ -611,6 +617,13 @@ def test_inherited_context(self):
611 617
         self.assertEqual(response.context['request-foo'], 'whiz')
612 618
         self.assertEqual(response.context['data'], 'bacon')
613 619
 
  620
+        try:
  621
+            response.context['does-not-exist']
  622
+            self.fail('Should not be able to retrieve non-existent key')
  623
+        except KeyError, e:
  624
+            self.assertEquals(e.message, 'does-not-exist')
  625
+
  626
+
614 627
 class SessionTests(TestCase):
615 628
     fixtures = ['testdata.json']
616 629
 

0 notes on commit f114fbe

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