def test_includes_work(self): self.add_path("test1", "hello world") contents = """ {% include "test1" %} """ self.assertEqual( render_string(self.context, contents, {})[0].strip(), "hello world")
def test_for_loop(self): contents = """ {% for f in foo %}{{ f }},{% endfor %} """ args = {"foo": [1, 2, 3]} self.assertEqual( render_string(self.context, contents, args)[0].strip(), "1,2,3,")
def test_allow_test_on_undefined(self): contents = """ {% if foo %} hello {% endif %} """ self.assertEqual( render_string(self.context, contents, {})[0].strip(), "")
def test_includes_can_access_vars(self): self.add_path("test1", "hello {{ name }}") contents = """ {% include "test1" %} """ args = {"name": "world"} self.assertEqual( render_string(self.context, contents, args)[0].strip(), "hello world")
def apply(self, context, output): name = self.resource.name.as_string() self.check_path(context, os.path.dirname(name), context.simulate) contents, sensitive = self.apply_patch(context, output) template_args = self.resource.template_args.resolve() if template_args: contents, secret = render_string(context, contents, template_args) sensitive = sensitive or secret fc = EnsureFile(name, contents, self.resource.owner.as_string(), self.resource.group.as_string(), self.resource.mode.resolve(), sensitive) context.change(fc) return fc.changed
def apply(self, context, output): name = self.resource.name.as_string() self.check_path(context, os.path.dirname(name), context.simulate) contents, sensitive = self.apply_patch(context, output) template_args = self.resource.template_args.resolve() if template_args: contents, secret = render_string(context, contents, template_args) sensitive = sensitive or secret fc = EnsureFile( name, contents, self.resource.owner.as_string(), self.resource.group.as_string(), self.resource.mode.resolve(), sensitive, ) context.change(fc) return fc.changed
def test_simple_variable(self): args = {"hello": "world"} self.assertEqual( render_string(self.context, "{{ hello }}", args)[0].strip(), "world")
def test_includes_tainted_by_secrets(self): self.add_path("test1", "hello: world\n", ['secret']) contents = """ {% include "test1" %} """ self.assertEqual(render_string(self.context, contents, {})[1], True)
def test_includes_not_secret_by_default(self): self.add_path("test1", "hello: world\n") contents = """ {% include "test1" %} """ self.assertEqual(render_string(self.context, contents, {})[1], False)