Add dedicated tests for jinja templates

This commit is contained in:
Jake Howard 2017-06-10 11:17:33 +01:00
parent 270b7195c7
commit f0c377d6b8
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 27 additions and 8 deletions

View file

@ -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
View 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)

View file

@ -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)