Пример #1
0
def test_SaltInvocationError_should_be_raised_when_file_is_missing():
    patch_exists = patch(
        "os.path.exists",
        Mock(return_value=False),
    )
    with patch_exists, pytest.raises(SaltInvocationError):
        filemod.lsattr("foo")
Пример #2
0
def test_if_lsattr_is_missing_it_should_return_None():
    patch_which = patch(
        "salt.utils.path.which",
        Mock(return_value=None),
    )
    with patch_which:
        actual = filemod.lsattr("foo")
        assert actual is None, actual
Пример #3
0
def test_on_aix_lsattr_should_be_None():
    patch_aix = patch(
        "salt.utils.platform.is_aix",
        Mock(return_value=True),
    )
    with patch_aix:
        # SaltInvocationError will be raised if filemod.lsattr
        # doesn't early exit
        actual = filemod.lsattr("foo")
        assert actual is None
Пример #4
0
def test_if_chattr_version_is_high_enough_then_extended_flags_should_be_returned(
):
    fname = "/path/to/fnord"
    with_extended = (textwrap.dedent("""
        aAcCdDeijPsStTu---- {}
        """).strip().format(fname))
    expected = set("aAcCdDeijPsStTu")
    patch_has_ext = patch(
        "salt.modules.file._chattr_has_extended_attrs",
        Mock(return_value=True),
    )
    patch_run = patch.dict(
        filemod.__salt__,
        {"cmd.run": Mock(return_value=with_extended)},
    )
    with patch_has_ext, patch_run:
        actual = set(filemod.lsattr(fname)[fname])
        msg = "Actual: {!r} Expected: {!r}".format(actual, expected)  # pylint: disable=E1322
        assert actual == expected, msg