Example #1
0
def test_remove():
    """
    Test to removes installed alternative for defined <name> and <path>
    or fallback to default alternative, if some defined before.
    """
    name = "pager"
    path = "/usr/bin/less"

    ret = {
        "name": name,
        "path": path,
        "result": None,
        "changes": {},
        "comment": ""
    }

    mock = MagicMock(side_effect=[True, True, True, False, False])
    mock_bool = MagicMock(return_value=True)
    mock_show = MagicMock(side_effect=[False, True, True, False])
    with patch.dict(
            alternatives.__salt__,
        {
            "alternatives.check_exists": mock,
            "alternatives.show_current": mock_show,
            "alternatives.remove": mock_bool,
        },
    ):
        comt = "Alternative for {} will be removed".format(name)
        ret.update({"comment": comt})
        with patch.dict(alternatives.__opts__, {"test": True}):
            assert alternatives.remove(name, path) == ret

        comt = "Alternative for {} removed".format(name)
        ret.update({"comment": comt, "result": True})
        with patch.dict(alternatives.__opts__, {"test": False}):
            assert alternatives.remove(name, path) == ret

        comt = "Alternative for pager removed. Falling back to path True"
        ret.update({
            "comment": comt,
            "result": True,
            "changes": {
                "path": True
            }
        })
        with patch.dict(alternatives.__opts__, {"test": False}):
            assert alternatives.remove(name, path) == ret

        comt = "Alternative for {} is set to it's default path True".format(
            name)
        ret.update({"comment": comt, "result": True, "changes": {}})
        assert alternatives.remove(name, path) == ret

        comt = "Alternative for {} doesn't exist".format(name)
        ret.update({"comment": comt, "result": False})
        assert alternatives.remove(name, path) == ret
Example #2
0
    def test_remove(self):
        '''
        Test to removes installed alternative for defined <name> and <path>
        or fallback to default alternative, if some defined before.
        '''
        name = 'pager'
        path = '/usr/bin/less'

        ret = {
            'name': name,
            'path': path,
            'result': None,
            'changes': {},
            'comment': ''
        }

        mock = MagicMock(side_effect=[True, True, True, False, False])
        mock_bool = MagicMock(return_value=True)
        mock_show = MagicMock(side_effect=[False, True, True, False])
        with patch.dict(
                alternatives.__salt__, {
                    'alternatives.check_exists': mock,
                    'alternatives.show_current': mock_show,
                    'alternatives.remove': mock_bool
                }):
            comt = ('Alternative for {0} will be removed'.format(name))
            ret.update({'comment': comt})
            with patch.dict(alternatives.__opts__, {'test': True}):
                self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for {0} removed'.format(name))
            ret.update({'comment': comt, 'result': True})
            with patch.dict(alternatives.__opts__, {'test': False}):
                self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for pager removed. Falling back to path True')
            ret.update({
                'comment': comt,
                'result': True,
                'changes': {
                    'path': True
                }
            })
            with patch.dict(alternatives.__opts__, {'test': False}):
                self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for {0} is set to it\'s default path True'
                    ).format(name)
            ret.update({'comment': comt, 'result': True, 'changes': {}})
            self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for {0} doesn\'t exist').format(name)
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(alternatives.remove(name, path), ret)
Example #3
0
    def test_remove(self):
        '''
        Test to removes installed alternative for defined <name> and <path>
        or fallback to default alternative, if some defined before.
        '''
        name = 'pager'
        path = '/usr/bin/less'

        ret = {'name': name,
               'path': path,
               'result': None,
               'changes': {},
               'comment': ''}

        mock = MagicMock(side_effect=[True, True, True, False, False])
        mock_bool = MagicMock(return_value=True)
        mock_show = MagicMock(side_effect=[False, True, True, False])
        with patch.dict(alternatives.__salt__,
                        {'alternatives.check_exists': mock,
                         'alternatives.show_current': mock_show,
                         'alternatives.remove': mock_bool}):
            comt = ('Alternative for {0} will be removed'.format(name))
            ret.update({'comment': comt})
            with patch.dict(alternatives.__opts__, {'test': True}):
                self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for {0} removed'.format(name))
            ret.update({'comment': comt, 'result': True})
            with patch.dict(alternatives.__opts__, {'test': False}):
                self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for pager removed. Falling back to path True')
            ret.update({'comment': comt, 'result': True,
                        'changes': {'path': True}})
            with patch.dict(alternatives.__opts__, {'test': False}):
                self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for {0} is set to it\'s default path True'
                   ).format(name)
            ret.update({'comment': comt, 'result': True, 'changes': {}})
            self.assertDictEqual(alternatives.remove(name, path), ret)

            comt = ('Alternative for {0} doesn\'t exist').format(name)
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(alternatives.remove(name, path), ret)