Add dedicated tests for jinja templates
This commit is contained in:
parent
270b7195c7
commit
f0c377d6b8
3 changed files with 27 additions and 8 deletions
|
@ -10,7 +10,6 @@ def render_content(content, context):
|
|||
'jinja2.ext.with_',
|
||||
'jinja2.ext.loopcontrols'
|
||||
]
|
||||
|
||||
)
|
||||
template = env.from_string(content)
|
||||
return template.render(**context)
|
||||
|
|
27
tests/test_jinja.py
Normal file
27
tests/test_jinja.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from tests import BaseTestCase
|
||||
from md_pdf.build.jinja import render_content
|
||||
|
||||
|
||||
class ContentRendererTestCase(BaseTestCase):
|
||||
def test_renders_template(self):
|
||||
html = 'test {{ test }}'
|
||||
output = render_content(html, self.extend_config({
|
||||
'test': 'content'
|
||||
}))
|
||||
self.assertEqual(output, 'test content')
|
||||
|
||||
def test_changes_nothing(self):
|
||||
html = 'test test'
|
||||
output = render_content(html, self.extend_config({
|
||||
'test': 'content'
|
||||
}))
|
||||
self.assertEqual(output, html)
|
||||
|
||||
def test_with_block(self):
|
||||
html = """
|
||||
{% with test = 'test' %}
|
||||
{{ test }} thing
|
||||
{% endwith %}
|
||||
"""
|
||||
output = render_content(html, self.BASE_VALID_CONFIG)
|
||||
self.assertIn('test thing', output)
|
|
@ -48,10 +48,3 @@ class RenderTemplateTestCase(BaseTestCase):
|
|||
'test': 'content'
|
||||
}))
|
||||
self.assertEqual(output, 'test content')
|
||||
|
||||
def test_changes_nothing(self):
|
||||
html = 'test test'
|
||||
output = content.render_template(html, self.extend_config({
|
||||
'test': 'content'
|
||||
}))
|
||||
self.assertEqual(output, html)
|
||||
|
|
Reference in a new issue