Exemplo n.º 1
0
    def test_list_pkgs(self):
        '''
        Test if it list the packages currently installed as a dict.
        '''
        mock_run = MagicMock(return_value='A\t B\t SAME')
        mock_ret = MagicMock(return_value=True)
        mock_pkg = MagicMock(return_value='')
        with patch.dict(pkgutil.__salt__,
                        {'cmd.run_stdout': mock_run,
                         'cmd.retcode': mock_ret,
                         'pkg_resource.stringify': mock_pkg,
                         'pkg_resource.sort_pkglist': mock_pkg,
                         'cmd.run': mock_run}):
            with patch.dict(pkgutil.__context__, {'pkg.list_pkgs': mock_ret}):
                self.assertDictEqual(pkgutil.list_pkgs(versions_as_list=True,
                                                       removed=True), {})

            self.assertDictEqual(pkgutil.list_pkgs(), {})

        with patch.dict(pkgutil.__context__, {'pkg.list_pkgs': True}):
            self.assertTrue(pkgutil.list_pkgs(versions_as_list=True))

            mock_pkg = MagicMock(return_value=True)
            with patch.dict(pkgutil.__salt__,
                            {'pkg_resource.stringify': mock_pkg}):
                self.assertTrue(pkgutil.list_pkgs())
Exemplo n.º 2
0
def test_list_pkgs_no_context():
    """
    Test if it list the packages currently installed as a dict.
    """
    mock_run = MagicMock(return_value="A\t B\t SAME")
    mock_ret = MagicMock(return_value=True)
    mock_pkg = MagicMock(return_value="")
    with patch.dict(
            pkgutil.__salt__,
        {
            "cmd.run_stdout": mock_run,
            "cmd.retcode": mock_ret,
            "pkg_resource.stringify": mock_pkg,
            "pkg_resource.sort_pkglist": mock_pkg,
            "cmd.run": mock_run,
        },
    ), patch.object(pkgutil,
                    "_list_pkgs_from_context") as list_pkgs_context_mock:
        pkgs = pkgutil.list_pkgs(versions_as_list=True,
                                 removed=True,
                                 use_context=False)
        list_pkgs_context_mock.assert_not_called()
        list_pkgs_context_mock.reset_mock()

        pkgs = pkgutil.list_pkgs(versions_as_list=True,
                                 removed=True,
                                 use_context=False)
        list_pkgs_context_mock.assert_not_called()
        list_pkgs_context_mock.reset_mock()
Exemplo n.º 3
0
def test_list_pkgs():
    """
    Test if it list the packages currently installed as a dict.
    """
    mock_run = MagicMock(return_value="A\t B\t SAME")
    mock_ret = MagicMock(return_value=True)
    mock_pkg = MagicMock(return_value="")
    with patch.dict(
            pkgutil.__salt__,
        {
            "cmd.run_stdout": mock_run,
            "cmd.retcode": mock_ret,
            "pkg_resource.stringify": mock_pkg,
            "pkg_resource.sort_pkglist": mock_pkg,
            "cmd.run": mock_run,
        },
    ):
        with patch.dict(pkgutil.__context__, {"pkg.list_pkgs": mock_ret}):
            assert pkgutil.list_pkgs(versions_as_list=True, removed=True) == {}

        assert pkgutil.list_pkgs() == {}

    with patch.dict(pkgutil.__context__, {"pkg.list_pkgs": True}):
        assert pkgutil.list_pkgs(versions_as_list=True)

        mock_pkg = MagicMock(return_value=True)
        with patch.dict(pkgutil.__salt__,
                        {"pkg_resource.stringify": mock_pkg}):
            assert pkgutil.list_pkgs()
Exemplo n.º 4
0
    def test_list_pkgs(self):
        '''
        Test if it list the packages currently installed as a dict.
        '''
        mock_run = MagicMock(return_value='A\t B\t SAME')
        mock_ret = MagicMock(return_value=True)
        mock_pkg = MagicMock(return_value='')
        with patch.dict(pkgutil.__salt__,
                        {'cmd.run_stdout': mock_run,
                         'cmd.retcode': mock_ret,
                         'pkg_resource.stringify': mock_pkg,
                         'pkg_resource.sort_pkglist': mock_pkg,
                         'cmd.run': mock_run}):
            with patch.dict(pkgutil.__context__, {'pkg.list_pkgs': mock_ret}):
                self.assertDictEqual(pkgutil.list_pkgs(versions_as_list=True,
                                                       removed=True), {})

            self.assertDictEqual(pkgutil.list_pkgs(), {})

        with patch.dict(pkgutil.__context__, {'pkg.list_pkgs': True}):
            self.assertTrue(pkgutil.list_pkgs(versions_as_list=True))

            mock_pkg = MagicMock(return_value=True)
            with patch.dict(pkgutil.__salt__,
                            {'pkg_resource.stringify': mock_pkg}):
                self.assertTrue(pkgutil.list_pkgs())