예제 #1
0
    def test_hold_pinned(self):
        """
        Tests holding if package is already pinned
        """
        mock_user = MagicMock(return_value="foo")
        mock_cmd = MagicMock(return_value="")
        mock_cmd_all = MagicMock(
            return_value={"pid": 12345, "retcode": 0, "stderr": "", "stdout": ""}
        )
        _expected = {
            "foo": {
                "changes": {},
                "comment": "Package foo is already set to be held.",
                "name": "foo",
                "result": True,
            }
        }

        mock_params = MagicMock(return_value=({"foo": None}, "repository"))
        with patch(
            "salt.modules.mac_brew_pkg.list_pkgs", return_value={"foo": "0.1.5"}
        ), patch(
            "salt.modules.mac_brew_pkg._list_pinned", return_value=["foo"]
        ), patch.dict(
            mac_brew.__salt__,
            {
                "file.get_user": mock_user,
                "pkg_resource.parse_targets": mock_params,
                "cmd.run_all": mock_cmd_all,
                "cmd.run": mock_cmd,
            },
        ):
            self.assertEqual(mac_brew.hold("foo"), _expected)
예제 #2
0
def test_hold_not_installed():
    """
    Tests holding if package is not installed
    """
    mock_user = MagicMock(return_value="foo")
    mock_cmd = MagicMock(return_value="")
    mock_cmd_all = MagicMock(
        return_value={"pid": 12345, "retcode": 0, "stderr": "", "stdout": ""}
    )
    _expected = {
        "foo": {
            "changes": {},
            "comment": "Package foo does not have a state.",
            "name": "foo",
            "result": False,
        }
    }

    mock_params = MagicMock(return_value=({"foo": None}, "repository"))
    with patch("salt.utils.path.which", MagicMock(return_value="/usr/local/bin/brew")):
        with patch("salt.modules.mac_brew_pkg.list_pkgs", return_value={}), patch.dict(
            mac_brew.__salt__,
            {
                "file.get_user": mock_user,
                "pkg_resource.parse_targets": mock_params,
                "cmd.run_all": mock_cmd_all,
                "cmd.run": mock_cmd,
            },
        ):
            assert mac_brew.hold("foo") == _expected