Fixed #12659 -- Return a more meaningful KeyError message when ContextList lookups fail. Thanks to rodriguealcazar for the suggestion.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12274 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7ca9d9306c
commit
f114fbecc2
|
@ -15,7 +15,7 @@ class ContextList(list):
|
||||||
for subcontext in self:
|
for subcontext in self:
|
||||||
if key in subcontext:
|
if key in subcontext:
|
||||||
return subcontext[key]
|
return subcontext[key]
|
||||||
raise KeyError
|
raise KeyError(key)
|
||||||
else:
|
else:
|
||||||
return super(ContextList, self).__getitem__(key)
|
return super(ContextList, self).__getitem__(key)
|
||||||
|
|
||||||
|
|
|
@ -602,6 +602,12 @@ class ContextTests(TestCase):
|
||||||
self.assertEqual(response.context['request-foo'], 'whiz')
|
self.assertEqual(response.context['request-foo'], 'whiz')
|
||||||
self.assertEqual(response.context['data'], 'sausage')
|
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):
|
def test_inherited_context(self):
|
||||||
"Context variables can be retrieved from a list of contexts"
|
"Context variables can be retrieved from a list of contexts"
|
||||||
response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
|
response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
|
||||||
|
@ -611,6 +617,13 @@ class ContextTests(TestCase):
|
||||||
self.assertEqual(response.context['request-foo'], 'whiz')
|
self.assertEqual(response.context['request-foo'], 'whiz')
|
||||||
self.assertEqual(response.context['data'], 'bacon')
|
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):
|
class SessionTests(TestCase):
|
||||||
fixtures = ['testdata.json']
|
fixtures = ['testdata.json']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue