示例#1
0
 def test_render_template(self):
     # render_template() should take a template string and substitue
     # its variables.
     pa = PowerAction(POWER_TYPE.WAKE_ON_LAN)
     template = ShellTemplate("template: {{mac}}")
     rendered = pa.render_template(template, mac="mymac")
     self.assertEqual("template: mymac", rendered)
示例#2
0
 def test_render_template_raises_PowerActionFail(self):
     # If not enough arguments are supplied to fill in template
     # variables then a PowerActionFail is raised.
     pa = PowerAction(POWER_TYPE.WAKE_ON_LAN)
     template_name = factory.getRandomString()
     template = ShellTemplate("template: {{mac}}", name=template_name)
     self.assertThat(
         lambda: pa.render_template(template),
         Raises(
             MatchesException(
                 PowerActionFail,
                 ".*name 'mac' is not defined at line \d+ column \d+ "
                 "in file %s" % re.escape(template_name))))
示例#3
0
 def test_substitute_does_not_escape_safe_objects(self):
     # Substitutions will not be escaped if they're `safe` objects.
     template = ShellTemplate("{{safe(a)}}")
     expected = "$ ! ()"
     observed = template.substitute(a="$ ! ()")
     self.assertEqual(expected, observed)
示例#4
0
 def test_substitute_does_not_escape_safe(self):
     # Substitutions will not be escaped if they're marked with `safe`.
     template = ShellTemplate("{{a|safe}}")
     expected = "$ ! ()"
     observed = template.substitute(a="$ ! ()")
     self.assertEqual(expected, observed)
示例#5
0
 def test_substitute_escapes(self):
     # Substitutions are shell-escaped.
     template = ShellTemplate("{{a}}")
     expected = "'1 2 3'"
     observed = template.substitute(a="1 2 3")
     self.assertEqual(expected, observed)
示例#6
0
 def test_substitute_does_not_escape_safe_objects(self):
     # Substitutions will not be escaped if they're `safe` objects.
     template = ShellTemplate("{{safe(a)}}")
     expected = "$ ! ()"
     observed = template.substitute(a="$ ! ()")
     self.assertEqual(expected, observed)
示例#7
0
 def test_substitute_does_not_escape_safe(self):
     # Substitutions will not be escaped if they're marked with `safe`.
     template = ShellTemplate("{{a|safe}}")
     expected = "$ ! ()"
     observed = template.substitute(a="$ ! ()")
     self.assertEqual(expected, observed)
示例#8
0
 def test_substitute_escapes(self):
     # Substitutions are shell-escaped.
     template = ShellTemplate("{{a}}")
     expected = "'1 2 3'"
     observed = template.substitute(a="1 2 3")
     self.assertEqual(expected, observed)
示例#9
0
 def get_template(self):
     with open(self.path, "rb") as f:
         return ShellTemplate(f.read(), name=self.path)