Author: russellm
Date: 2010-01-22 09:31:14 -0600 (Fri, 22 Jan 2010)
New Revision: 12274

Modified:
   django/trunk/django/test/utils.py
   django/trunk/tests/regressiontests/test_client_regress/models.py
Log:
Fixed #12659 -- Return a more meaningful KeyError message when ContextList 
lookups fail. Thanks to rodriguealcazar for the suggestion.

Modified: django/trunk/django/test/utils.py
===================================================================
--- django/trunk/django/test/utils.py   2010-01-22 15:02:02 UTC (rev 12273)
+++ django/trunk/django/test/utils.py   2010-01-22 15:31:14 UTC (rev 12274)
@@ -15,7 +15,7 @@
             for subcontext in self:
                 if key in subcontext:
                     return subcontext[key]
-            raise KeyError
+            raise KeyError(key)
         else:
             return super(ContextList, self).__getitem__(key)
 

Modified: django/trunk/tests/regressiontests/test_client_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/test_client_regress/models.py    
2010-01-22 15:02:02 UTC (rev 12273)
+++ django/trunk/tests/regressiontests/test_client_regress/models.py    
2010-01-22 15:31:14 UTC (rev 12274)
@@ -602,6 +602,12 @@
         self.assertEqual(response.context['request-foo'], 'whiz')
         self.assertEqual(response.context['data'], 'sausage')
 
+        try:
+            response.context['does-not-exist']
+            self.fail('Should not be able to retrieve non-existent key')
+        except KeyError, e:
+            self.assertEquals(e.message, 'does-not-exist')
+
     def test_inherited_context(self):
         "Context variables can be retrieved from a list of contexts"
         response = 
self.client.get("/test_client_regress/request_data_extended/", 
data={'foo':'whiz'})
@@ -611,6 +617,13 @@
         self.assertEqual(response.context['request-foo'], 'whiz')
         self.assertEqual(response.context['data'], 'bacon')
 
+        try:
+            response.context['does-not-exist']
+            self.fail('Should not be able to retrieve non-existent key')
+        except KeyError, e:
+            self.assertEquals(e.message, 'does-not-exist')
+
+
 class SessionTests(TestCase):
     fixtures = ['testdata.json']
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to