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

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

        with patch.dict(
                dism.__salt__, {
                    'dism.installed_packages': mock_removed,
                    'dism.remove_package': mock_remove,
                    'dism.package_info': mock_info
                }):

            with patch.dict(dism.__opts__, {'test': False}):
                with patch('os.path.exists'):
                    out = dism.package_removed('Pack2')

                    mock_removed.assert_called_once_with()
                    assert not mock_remove.called
                    self.assertEqual(out, expected)
Ejemplo n.º 2
0
    def test_package_removed(self):
        '''
            Test removing a package with DISM
        '''
        expected = {
            'comment': "Removed Pack2",
            'changes': {
                'package': {
                    'old': 'Pack2'
                },
                'retcode': 0
            },
            'name': 'Pack2',
            'result': True
        }

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

        with patch.dict(
                dism.__salt__, {
                    'dism.installed_packages': mock_removed,
                    'dism.remove_package': mock_remove,
                    'dism.package_info': mock_info
                }):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.package_removed('Pack2')

                mock_removed.assert_called_with()
                mock_remove.assert_called_once_with('Pack2', None, False)
                self.assertEqual(out, expected)
Ejemplo n.º 3
0
    def test_package_removed_failure(self):
        '''
            Test removing a package which fails with DISM
        '''
        expected = {
            'comment': "Failed to remove Pack2: Failed",
            'changes': {},
            'name': 'Pack2',
            'result': False
        }

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

        with patch.dict(
                dism.__salt__, {
                    'dism.installed_packages': mock_removed,
                    'dism.remove_package': mock_remove,
                    'dism.package_info': mock_info
                }):
            with patch.dict(dism.__opts__, {'test': False}):
                with patch('os.path.exists'):

                    out = dism.package_removed('Pack2')

                    mock_removed.assert_called_with()
                    mock_remove.assert_called_once_with('Pack2', None, False)
                    self.assertEqual(out, expected)
Ejemplo n.º 4
0
def test_package_removed_removed():
    """
    Test removing a package already removed
    """
    expected = {
        "comment": "The package Pack2 is already removed",
        "changes": {},
        "name": "Pack2",
        "result": True,
    }

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

    with patch.dict(
            dism.__salt__,
        {
            "dism.installed_packages": mock_removed,
            "dism.remove_package": mock_remove,
            "dism.package_info": mock_info,
        },
    ):

        with patch.dict(dism.__opts__, {"test": False}):
            with patch("os.path.exists"):
                out = dism.package_removed("Pack2")

                mock_removed.assert_called_once_with()
                assert not mock_remove.called
                assert out == expected
Ejemplo n.º 5
0
def test_package_removed_failure():
    """
    Test removing a package which fails with DISM
    """
    expected = {
        "comment": "Failed to remove Pack2: Failed",
        "changes": {},
        "name": "Pack2",
        "result": False,
    }

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

    with patch.dict(
            dism.__salt__,
        {
            "dism.installed_packages": mock_removed,
            "dism.remove_package": mock_remove,
            "dism.package_info": mock_info,
        },
    ):
        with patch.dict(dism.__opts__, {"test": False}):
            with patch("os.path.exists"):

                out = dism.package_removed("Pack2")

                mock_removed.assert_called_with()
                mock_remove.assert_called_once_with("Pack2", None, False)
                assert out == expected
Ejemplo n.º 6
0
    def test_package_removed_removed(self):
        '''
            Test removing a package already removed
        '''
        expected = {
            'comment': "The package Pack2 is already removed",
            'changes': {},
            'name': 'Pack2',
            'result': True}

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

        with patch.dict(
            dism.__salt__, {'dism.installed_packages': mock_removed,
                            'dism.remove_package': mock_remove,
                            'dism.package_info': mock_info}):

            out = dism.package_removed('Pack2')

            mock_removed.assert_called_once_with()
            assert not mock_remove.called
            self.assertEqual(out, expected)
Ejemplo n.º 7
0
    def test_package_removed_failure(self):
        '''
            Test removing a package which fails with DISM
        '''
        expected = {
            'comment': "Failed to remove Pack2: Failed",
            'changes': {},
            'name': 'Pack2',
            'result': False}

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

        with patch.dict(
            dism.__salt__, {'dism.installed_packages': mock_removed,
                            'dism.remove_package': mock_remove,
                            'dism.package_info': mock_info}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.package_removed('Pack2')

                mock_removed.assert_called_with()
                mock_remove.assert_called_once_with(
                    'Pack2', None, False)
                self.assertEqual(out, expected)
Ejemplo n.º 8
0
    def test_package_removed(self):
        """
            Test removing a package with DISM
        """
        expected = {
            "comment": "Removed Pack2",
            "changes": {
                "package": {
                    "old": ["Pack2"]
                },
                "retcode": 0
            },
            "name": "Pack2",
            "result": True,
        }

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

        with patch.dict(
                dism.__salt__,
            {
                "dism.installed_packages": mock_removed,
                "dism.remove_package": mock_remove,
                "dism.package_info": mock_info,
            },
        ):
            with patch.dict(dism.__opts__, {"test": False}):
                with patch("os.path.exists"):

                    out = dism.package_removed("Pack2")

                    mock_removed.assert_called_with()
                    mock_remove.assert_called_once_with("Pack2", None, False)
                    self.assertEqual(out, expected)