3
# Copyright (C) 2014 Yahoo! Inc.
5
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 3, as
9
# published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
from tests.unittests import helpers as test_helpers
22
from cloudinit import templater
25
class TestTemplates(test_helpers.TestCase):
26
def test_detection(self):
27
blob = "## template:cheetah"
29
(template_type, contents) = templater.detect_template(blob)
30
self.assertEqual("cheetah", template_type)
31
self.assertEqual("", contents.strip())
33
blob = "blahblah $blah"
34
(template_type, contents) = templater.detect_template(blob)
35
self.assertEqual("cheetah", template_type)
36
self.assertEquals(blob, contents)
38
blob = '##template:something-new'
39
self.assertRaises(ValueError, templater.detect_template, blob)
41
def test_render_cheetah(self):
42
blob = '''## template:cheetah
44
c = templater.render_string(blob, {"a": 1, "b": 2})
45
self.assertEquals("1,2", c)
47
def test_render_jinja(self):
48
blob = '''## template:jinja
50
c = templater.render_string(blob, {"a": 1, "b": 2})
51
self.assertEquals("1,2", c)
53
def test_render_default(self):
55
c = templater.render_string(blob, {"a": 1, "b": 2})
56
self.assertEquals("1,2", c)