From f0c377d6b8100c2dc73782250345a263dba71c59 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 10 Jun 2017 11:17:33 +0100 Subject: [PATCH] Add dedicated tests for jinja templates --- md_pdf/build/jinja.py | 1 - tests/test_jinja.py | 27 +++++++++++++++++++++++++++ tests/test_parser.py | 7 ------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 tests/test_jinja.py diff --git a/md_pdf/build/jinja.py b/md_pdf/build/jinja.py index d5f0687..7d1e115 100644 --- a/md_pdf/build/jinja.py +++ b/md_pdf/build/jinja.py @@ -10,7 +10,6 @@ def render_content(content, context): 'jinja2.ext.with_', 'jinja2.ext.loopcontrols' ] - ) template = env.from_string(content) return template.render(**context) diff --git a/tests/test_jinja.py b/tests/test_jinja.py new file mode 100644 index 0000000..2c4af8f --- /dev/null +++ b/tests/test_jinja.py @@ -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) diff --git a/tests/test_parser.py b/tests/test_parser.py index ec28f5f..41acc67 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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)