Migrate tests/integration/renderers/test_jinja.py to pytest

This commit is contained in:
MKLeb 2023-10-04 12:43:25 -04:00 committed by Pedro Algarvio
parent 83ab0d8807
commit 55b1ff7b64
2 changed files with 36 additions and 36 deletions

View file

@ -1,36 +0,0 @@
import os
import pytest
import salt.utils.files
from tests.support.case import ModuleCase, ShellCase
from tests.support.helpers import with_tempdir
class JinjaRendererTest(ModuleCase):
@with_tempdir()
@pytest.mark.slow_test
def test_issue_54765(self, tmpdir):
file_path = os.path.join(tmpdir, "issue-54765")
ret = self.run_function(
"state.sls", mods="issue-54765", pillar={"file_path": file_path}
)
key = "file_|-issue-54765_|-{}_|-managed".format(file_path)
assert key in ret
assert ret[key]["result"] is True
with salt.utils.files.fopen(file_path, "r") as fp:
assert fp.read().strip() == "bar"
class JinjaRenderCallTest(ShellCase):
@with_tempdir()
@pytest.mark.slow_test
def test_issue_54765(self, tmpdir):
file_path = os.path.join(tmpdir, "issue-54765")
pillar_str = '\'{{"file_path": "{}"}}\''.format(file_path)
ret = self.run_call(
"state.apply issue-54765 pillar={}".format(pillar_str), local=True
)
assert " Result: True" in ret
with salt.utils.files.fopen(file_path, "r") as fp:
assert fp.read().strip() == "bar"

View file

@ -0,0 +1,36 @@
import pytest
import salt.utils.files
pytestmark = [
pytest.mark.slow_test,
]
def test_issue_54765_salt(tmp_path, salt_cli, salt_minion):
file_path = str(tmp_path / "issue-54765")
ret = salt_cli.run(
"state.sls",
mods="issue-54765",
pillar={"file_path": file_path},
minion_tgt=salt_minion.id,
).data
key = "file_|-issue-54765_|-{}_|-managed".format(file_path)
assert key in ret
assert ret[key]["result"] is True
with salt.utils.files.fopen(file_path, "r") as fp:
assert fp.read().strip() == "bar"
def test_issue_54765_call(tmp_path, salt_call_cli):
file_path = str(tmp_path / "issue-54765")
ret = salt_call_cli.run(
"--local",
"state.apply",
"issue-54765",
pillar=f"{{'file_path': '{file_path}'}}",
)
key = "file_|-issue-54765_|-{}_|-managed".format(file_path)
assert ret.data[key]["result"] is True
with salt.utils.files.fopen(file_path, "r") as fp:
assert fp.read().strip() == "bar"