summaryrefslogtreecommitdiff
path: root/tests/template_tests/test_context.py
diff options
context:
space:
mode:
authorBuddy Lindsey, Jr <buddy@buddylindsey.com>2015-09-10 15:54:19 -0500
committerTim Graham <timograham@gmail.com>2015-09-11 14:52:13 -0400
commitec704371e301c5450dd5fc012a30424a8f47b99b (patch)
tree16a5f607be277ec46bc83b88b1f0da9580b5ed31 /tests/template_tests/test_context.py
parente7e8d30cae9457339eb49ae8584e82ff0a038e99 (diff)
Fixed #24765 -- Allowed template context updates to flatten a Context.
Diffstat (limited to 'tests/template_tests/test_context.py')
-rw-r--r--tests/template_tests/test_context.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/template_tests/test_context.py b/tests/template_tests/test_context.py
index d07edd3ef1..87b2016aa5 100644
--- a/tests/template_tests/test_context.py
+++ b/tests/template_tests/test_context.py
@@ -43,6 +43,46 @@ class ContextTests(SimpleTestCase):
self.assertEqual(c['a'], 3)
self.assertEqual(c['a'], 1)
+ def test_push_context_manager_with_context_object(self):
+ c = Context({'a': 1})
+ with c.push(Context({'a': 3})):
+ self.assertEqual(c['a'], 3)
+ self.assertEqual(c['a'], 1)
+
+ def test_update_context_manager_with_context_object(self):
+ c = Context({'a': 1})
+ with c.update(Context({'a': 3})):
+ self.assertEqual(c['a'], 3)
+ self.assertEqual(c['a'], 1)
+
+ def test_push_proper_layering(self):
+ c = Context({'a': 1})
+ c.push(Context({'b': 2}))
+ c.push(Context({'c': 3, 'd': {'z': '26'}}))
+ self.assertEqual(
+ c.dicts,
+ [
+ {'False': False, 'None': None, 'True': True},
+ {'a': 1},
+ {'b': 2},
+ {'c': 3, 'd': {'z': '26'}},
+ ]
+ )
+
+ def test_update_proper_layering(self):
+ c = Context({'a': 1})
+ c.update(Context({'b': 2}))
+ c.update(Context({'c': 3, 'd': {'z': '26'}}))
+ self.assertEqual(
+ c.dicts,
+ [
+ {'False': False, 'None': None, 'True': True},
+ {'a': 1},
+ {'b': 2},
+ {'c': 3, 'd': {'z': '26'}},
+ ]
+ )
+
def test_setdefault(self):
c = Context()
@@ -96,6 +136,20 @@ class ContextTests(SimpleTestCase):
'a': 2, 'b': 4, 'c': 8
})
+ def test_flatten_context_with_context(self):
+ """
+ Context.push() with a Context argument should work.
+ """
+ a = Context({'a': 2})
+ a.push(Context({'z': '8'}))
+ self.assertEqual(a.flatten(), {
+ 'False': False,
+ 'None': None,
+ 'True': True,
+ 'a': 2,
+ 'z': '8',
+ })
+
def test_context_comparable(self):
"""
#21765 -- equality comparison should work