summaryrefslogtreecommitdiff
path: root/tests/template_tests/test_context.py
diff options
context:
space:
mode:
authorAlexander Schrijver <alex@flupzor.nl>2016-07-16 22:55:40 +0200
committerTim Graham <timograham@gmail.com>2016-08-09 09:05:17 -0400
commit3ae3a1f9fad800d73892b14ac8a576e817a2da55 (patch)
tree3ddbfc34b1c8f9dd76702b581f2364c4e7e85a71 /tests/template_tests/test_context.py
parent31e053edfa01e47c26dfa03834beeba77e09403a (diff)
Fixed #26830 -- Prevented the 'with' templatetag from resetting the cycle variable to its initial state.
Diffstat (limited to 'tests/template_tests/test_context.py')
-rw-r--r--tests/template_tests/test_context.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/template_tests/test_context.py b/tests/template_tests/test_context.py
index 94011fb0f1..c061610a19 100644
--- a/tests/template_tests/test_context.py
+++ b/tests/template_tests/test_context.py
@@ -204,6 +204,37 @@ class ContextTests(SimpleTestCase):
self.assertEqual(str(warns[2].message), msg2)
self.assertEqual(str(warns[3].message), msg2)
+ def test_set_upward(self):
+ c = Context({'a': 1})
+ c.set_upward('a', 2)
+ self.assertEqual(c.get('a'), 2)
+
+ def test_set_upward_empty_context(self):
+ empty_context = Context()
+ empty_context.set_upward('a', 1)
+ self.assertEqual(empty_context.get('a'), 1)
+
+ def test_set_upward_with_push(self):
+ """
+ The highest context which has the given key is used.
+ """
+ c = Context({'a': 1})
+ c.push({'a': 2})
+ c.set_upward('a', 3)
+ self.assertEqual(c.get('a'), 3)
+ c.pop()
+ self.assertEqual(c.get('a'), 1)
+
+ def test_set_upward_with_push_no_match(self):
+ """
+ The highest context is used if the given key isn't found.
+ """
+ c = Context({'b': 1})
+ c.push({'b': 2})
+ c.set_upward('a', 2)
+ self.assertEqual(len(c.dicts), 3)
+ self.assertEqual(c.dicts[-1]['a'], 2)
+
class RequestContextTests(SimpleTestCase):