Fix: original template was partial overwritten, thus the rendered output was never updated
This commit is contained in:
parent
b9269146e1
commit
50508b2328
2 changed files with 18 additions and 6 deletions
|
@ -43,14 +43,10 @@ def render_traverse(obj):
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, list):
|
if isinstance(obj, list):
|
||||||
# list -> recurse into each item
|
# list -> recurse into each item
|
||||||
for i in range(len(obj)):
|
return [render_traverse(x) for x in obj]
|
||||||
obj[i] = render_traverse(obj[i])
|
|
||||||
return obj
|
|
||||||
elif isinstance(obj, dict):
|
elif isinstance(obj, dict):
|
||||||
# dict -> recurse into the value of each (key, value)
|
# dict -> recurse into the value of each (key, value)
|
||||||
for k, v in obj.items():
|
return {k: render_traverse(v) for k, v in obj.items()}
|
||||||
obj[k] = render_traverse(obj[k])
|
|
||||||
return obj
|
|
||||||
elif isinstance(obj, str):
|
elif isinstance(obj, str):
|
||||||
# str -> template
|
# str -> template
|
||||||
return render(obj)
|
return render(obj)
|
||||||
|
|
|
@ -22,6 +22,15 @@ class TemplateTest(unittest.TestCase):
|
||||||
def template_test_test(value):
|
def template_test_test(value):
|
||||||
return value == 'baz'
|
return value == 'baz'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@template_function
|
||||||
|
def template_test_function_nocache():
|
||||||
|
TemplateTest.counter1 += 1
|
||||||
|
return TemplateTest.counter1
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
TemplateTest.counter1 = 0
|
||||||
|
|
||||||
def test_template(self):
|
def test_template(self):
|
||||||
env = _env_init()
|
env = _env_init()
|
||||||
self.assertEqual('"not a template"', env.from_string('not a template').render())
|
self.assertEqual('"not a template"', env.from_string('not a template').render())
|
||||||
|
@ -60,3 +69,10 @@ class TemplateTest(unittest.TestCase):
|
||||||
self.assertEqual('test_other_bar', rendered['test_functions']['test_filter'])
|
self.assertEqual('test_other_bar', rendered['test_functions']['test_filter'])
|
||||||
self.assertTrue(rendered['test_functions']['test_test_true'])
|
self.assertTrue(rendered['test_functions']['test_test_true'])
|
||||||
self.assertFalse(rendered['test_functions']['test_test_false'])
|
self.assertFalse(rendered['test_functions']['test_test_false'])
|
||||||
|
|
||||||
|
def test_no_cache(self):
|
||||||
|
template = ['{{ template_test_function_nocache() }}']
|
||||||
|
r1 = render_traverse(template)
|
||||||
|
r2 = render_traverse(template)
|
||||||
|
self.assertEqual(1, r1[0])
|
||||||
|
self.assertEqual(2, r2[0])
|
||||||
|
|
Loading…
Reference in a new issue