From 7f7fa2f91467fdb2b11312be8562e7b51fdeb199 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <sebastian.koslowski@gmail.com>
Date: Tue, 3 May 2016 17:13:08 +0200
Subject: grc: added yaml/mako support

Includes basic converter from XML/Cheetah to YAML/Mako based block format.
---
 grc/tests/test_block_templates.py | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 grc/tests/test_block_templates.py

(limited to 'grc/tests/test_block_templates.py')

diff --git a/grc/tests/test_block_templates.py b/grc/tests/test_block_templates.py
new file mode 100644
index 0000000000..df9ab37550
--- /dev/null
+++ b/grc/tests/test_block_templates.py
@@ -0,0 +1,45 @@
+import pytest
+
+from grc.core.blocks._templates import MakoTemplates
+from grc.core.errors import TemplateError
+
+
+class Block(object):
+    namespace_templates = {}
+
+    templates = MakoTemplates(None)
+
+    def __init__(self, **kwargs):
+        self.namespace_templates.update(kwargs)
+
+
+def test_simple():
+    t = MakoTemplates(_bind_to=Block(num='123'), test='abc${num}')
+    assert t['test'] == 'abc${num}'
+    assert t.render('test') == 'abc123'
+    assert 'abc${num}' in t._template_cache
+
+
+def test_instance():
+    block = Block(num='123')
+    block.templates['test'] = 'abc${num}'
+    assert block.templates.render('test') == 'abc123'
+    assert block.templates is block.__dict__['templates']
+
+
+def test_list():
+    templates = ['abc${num}', '${2 * num}c']
+    t = MakoTemplates(_bind_to=Block(num='123'), test=templates)
+    assert t['test'] == templates
+    assert t.render('test') == ['abc123', '123123c']
+    assert set(templates) == set(t._template_cache.keys())
+
+
+def test_parse_error():
+    with pytest.raises(TemplateError):
+        MakoTemplates(_bind_to=Block(num='123'), test='abc${num NOT CLOSING').render('test')
+
+
+def test_parse_error2():
+    with pytest.raises(TemplateError):
+        MakoTemplates(_bind_to=Block(num='123'), test='abc${ WRONG_VAR }').render('test')
-- 
cgit v1.2.3