Ejemplo n.º 1
0
    def test_package_installed_installed(self):
        '''
            Test installing a package already installed
        '''
        expected = {
            'comment': "The package Pack2 is already installed: Pack2",
            'changes': {},
            'name': 'Pack2',
            'result': True
        }

        mock_installed = MagicMock(
            side_effect=[['Pack1', 'Pack2'], ['Pack1', 'Pack2']])
        mock_add = MagicMock()
        mock_info = MagicMock(return_value={'Package Identity': 'Pack2'})

        with patch.dict(
                dism.__salt__, {
                    'dism.installed_packages': mock_installed,
                    'dism.add_package': mock_add,
                    'dism.package_info': mock_info
                }):
            with patch.dict(dism.__opts__, {'test': False}):
                with patch('os.path.exists'):

                    out = dism.package_installed('Pack2')

                    mock_installed.assert_called_once_with()
                    assert not mock_add.called
                    self.assertEqual(out, expected)
Ejemplo n.º 2
0
    def test_package_installed(self):
        '''
            Test installing a package with DISM
        '''
        expected = {
            'comment': "Installed Pack2",
            'changes': {
                'package': {
                    'new': 'Pack2'
                },
                'retcode': 0
            },
            'name': 'Pack2',
            'result': True
        }

        mock_installed = MagicMock(side_effect=[['Pack1'], ['Pack1', 'Pack2']])
        mock_add = MagicMock(return_value={'retcode': 0})
        mock_info = MagicMock(return_value={'Package Identity': 'Pack2'})

        with patch.dict(
                dism.__salt__, {
                    'dism.installed_packages': mock_installed,
                    'dism.add_package': mock_add,
                    'dism.package_info': mock_info
                }):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.package_installed('Pack2')

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with('Pack2', False, False, None,
                                                 False)
                self.assertEqual(out, expected)
Ejemplo n.º 3
0
    def test_package_installed_failure(self):
        '''
            Test installing a package which fails with DISM
        '''
        expected = {
            'comment': "Failed to install Pack2: Failed",
            'changes': {},
            'name': 'Pack2',
            'result': False
        }

        mock_installed = MagicMock(side_effect=[['Pack1'], ['Pack1']])
        mock_add = MagicMock(return_value={'retcode': 67, 'stdout': 'Failed'})
        mock_info = MagicMock(return_value={'Package Identity': 'Pack2'})

        with patch.dict(
                dism.__salt__, {
                    'dism.installed_packages': mock_installed,
                    'dism.add_package': mock_add,
                    'dism.package_info': mock_info
                }):
            with patch.dict(dism.__opts__, {'test': False}):
                with patch('os.path.exists'):

                    out = dism.package_installed('Pack2')

                    mock_installed.assert_called_with()
                    mock_add.assert_called_once_with('Pack2', False, False,
                                                     None, False)
                    self.assertEqual(out, expected)
Ejemplo n.º 4
0
def test_package_installed_installed():
    """
    Test installing a package already installed
    """
    expected = {
        "comment": "The package Pack2 is already installed: Pack2",
        "changes": {},
        "name": "Pack2",
        "result": True,
    }

    mock_installed = MagicMock(
        side_effect=[["Pack1", "Pack2"], ["Pack1", "Pack2"]])
    mock_add = MagicMock()
    mock_info = MagicMock(return_value={"Package Identity": "Pack2"})

    with patch.dict(
            dism.__salt__,
        {
            "dism.installed_packages": mock_installed,
            "dism.add_package": mock_add,
            "dism.package_info": mock_info,
        },
    ):
        with patch.dict(dism.__opts__, {"test": False}):
            with patch("os.path.exists"):

                out = dism.package_installed("Pack2")

                mock_installed.assert_called_once_with()
                assert not mock_add.called
                assert out == expected
Ejemplo n.º 5
0
def test_package_installed_failure():
    """
    Test installing a package which fails with DISM
    """
    expected = {
        "comment": "Failed to install Pack2: Failed",
        "changes": {},
        "name": "Pack2",
        "result": False,
    }

    mock_installed = MagicMock(side_effect=[["Pack1"], ["Pack1"]])
    mock_add = MagicMock(return_value={"retcode": 67, "stdout": "Failed"})
    mock_info = MagicMock(return_value={"Package Identity": "Pack2"})

    with patch.dict(
            dism.__salt__,
        {
            "dism.installed_packages": mock_installed,
            "dism.add_package": mock_add,
            "dism.package_info": mock_info,
        },
    ):
        with patch.dict(dism.__opts__, {"test": False}):
            with patch("os.path.exists"):

                out = dism.package_installed("Pack2")

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with("Pack2", False, False, None,
                                                 False)
                assert out == expected
Ejemplo n.º 6
0
    def test_package_installed_installed(self):
        '''
            Test installing a package already installed
        '''
        expected = {
            'comment': "The package Pack2 is already installed: Pack2",
            'changes': {},
            'name': 'Pack2',
            'result': True}

        mock_installed = MagicMock(
            side_effect=[['Pack1', 'Pack2'], ['Pack1', 'Pack2']])
        mock_add = MagicMock()
        mock_info = MagicMock(
            return_value={'Package Identity': 'Pack2'})

        with patch.dict(
            dism.__salt__, {'dism.installed_packages': mock_installed,
                            'dism.add_package': mock_add,
                            'dism.package_info': mock_info}):

            out = dism.package_installed('Pack2')

            mock_installed.assert_called_once_with()
            assert not mock_add.called
            self.assertEqual(out, expected)
Ejemplo n.º 7
0
    def test_package_installed_failure(self):
        '''
            Test installing a package which fails with DISM
        '''
        expected = {
            'comment': "Failed to install Pack2: Failed",
            'changes': {},
            'name': 'Pack2',
            'result': False}

        mock_installed = MagicMock(
            side_effect=[['Pack1'], ['Pack1']])
        mock_add = MagicMock(
            return_value={'retcode': 67, 'stdout': 'Failed'})
        mock_info = MagicMock(
            return_value={'Package Identity': 'Pack2'})

        with patch.dict(
            dism.__salt__, {'dism.installed_packages': mock_installed,
                            'dism.add_package': mock_add,
                            'dism.package_info': mock_info}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.package_installed('Pack2')

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with(
                    'Pack2', False, False, None, False)
                self.assertEqual(out, expected)
Ejemplo n.º 8
0
    def test_package_installed(self):
        """
            Test installing a package with DISM
        """
        expected = {
            "comment": "Installed Pack2",
            "changes": {
                "package": {
                    "new": ["Pack2"]
                },
                "retcode": 0
            },
            "name": "Pack2",
            "result": True,
        }

        mock_installed = MagicMock(side_effect=[["Pack1"], ["Pack1", "Pack2"]])
        mock_add = MagicMock(return_value={"retcode": 0})
        mock_info = MagicMock(return_value={"Package Identity": "Pack2"})

        with patch.dict(
                dism.__salt__,
            {
                "dism.installed_packages": mock_installed,
                "dism.add_package": mock_add,
                "dism.package_info": mock_info,
            },
        ):
            with patch.dict(dism.__opts__, {"test": False}):
                with patch("os.path.exists"):

                    out = dism.package_installed("Pack2")

                    mock_installed.assert_called_with()
                    mock_add.assert_called_once_with("Pack2", False, False,
                                                     None, False)
                    self.assertEqual(out, expected)