1
0

test_jinja.py 1.4 KB

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