test_jinja.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import os
  4. import salt.utils.files
  5. from tests.support.case import ModuleCase, ShellCase
  6. from tests.support.helpers import slowTest, with_tempdir
  7. class JinjaRendererTest(ModuleCase):
  8. @with_tempdir()
  9. @slowTest
  10. def test_issue_54765(self, tmpdir):
  11. file_path = os.path.join(tmpdir, "issue-54765")
  12. ret = self.run_function(
  13. "state.sls", mods="issue-54765", pillar={"file_path": file_path}
  14. )
  15. key = "file_|-issue-54765_|-{}_|-managed".format(file_path)
  16. assert key in ret
  17. assert ret[key]["result"] is True
  18. with salt.utils.files.fopen(file_path, "r") as fp:
  19. assert fp.read().strip() == "bar"
  20. class JinjaRenderCallTest(ShellCase):
  21. @with_tempdir()
  22. @slowTest
  23. def test_issue_54765(self, tmpdir):
  24. file_path = os.path.join(tmpdir, "issue-54765")
  25. pillar_str = '\'{{"file_path": "{}"}}\''.format(file_path)
  26. ret = self.run_call(
  27. "state.apply issue-54765 pillar={}".format(pillar_str), local=True
  28. )
  29. assert " Result: True" in ret
  30. with salt.utils.files.fopen(file_path, "r") as fp:
  31. assert fp.read().strip() == "bar"