diff options
| author | Alex Hill <alex@hill.net.au> | 2013-12-19 13:42:32 +0800 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-12-20 01:02:50 +0100 |
| commit | 832ab0dbaacf381d15445259f292d88175ff84f2 (patch) | |
| tree | 20239d25f377753cdde47a4c612332dcbe340776 /tests | |
| parent | 23d9f517dc3ca31816bb8596f5a59f1ae44304ee (diff) | |
Fixed #21639 -- Implemented RenderContext.__getitem__
It's now consistent with RenderContext.get.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/template_tests/test_context.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/template_tests/test_context.py b/tests/template_tests/test_context.py index 7bcfb7f9f2..bbf6918103 100644 --- a/tests/template_tests/test_context.py +++ b/tests/template_tests/test_context.py @@ -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')) |
