mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #21639 -- Implemented RenderContext.__getitem__
It's now consistent with RenderContext.get.
This commit is contained in:
committed by
Baptiste Mispelon
parent
23d9f517dc
commit
832ab0dbaa
@@ -3,6 +3,7 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from django.template import Context, Variable, VariableDoesNotExist
|
||||
from django.template.context import RenderContext
|
||||
|
||||
|
||||
class ContextTests(TestCase):
|
||||
@@ -34,3 +35,17 @@ class ContextTests(TestCase):
|
||||
self.assertRaises(VariableDoesNotExist,
|
||||
Variable('new').resolve, empty_context)
|
||||
self.assertEqual(Variable('new').resolve(Context({'new': 'foo'})), 'foo')
|
||||
|
||||
def test_render_context(self):
|
||||
test_context = RenderContext({'fruit': 'papaya'})
|
||||
|
||||
# Test that push() limits access to the topmost dict
|
||||
test_context.push()
|
||||
|
||||
test_context['vegetable'] = 'artichoke'
|
||||
self.assertEqual(list(test_context), ['vegetable'])
|
||||
|
||||
self.assertNotIn('fruit', test_context)
|
||||
with self.assertRaises(KeyError):
|
||||
test_context['fruit']
|
||||
self.assertIsNone(test_context.get('fruit'))
|
||||
|
||||
Reference in New Issue
Block a user