Пример #1
0
    def test_set(self):
        '''
        Test to sets alternative for <name> to <path>, if <path> is defined
        as an alternative for <name>.
        '''
        name = 'pager'
        path = '/usr/bin/less'

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

        mock = MagicMock(side_effect=[path, path, ''])
        mock_bool = MagicMock(return_value=True)
        mock_show = MagicMock(side_effect=[path, False, False, False, False])
        with patch.dict(
                alternatives.__salt__, {
                    'alternatives.display': mock,
                    'alternatives.show_current': mock_show,
                    'alternatives.set': mock_bool
                }):
            comt = ('Alternative for {0} already set to {1}'.format(
                name, path))
            ret.update({'comment': comt})
            self.assertDictEqual(alternatives.set_(name, path), ret)

            comt = (
                'Alternative for {0} will be set to path False').format(name)
            ret.update({'comment': comt, 'result': None})
            with patch.dict(alternatives.__opts__, {'test': True}):
                self.assertDictEqual(alternatives.set_(name, path), ret)

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

            comt = ('Alternative {0} for {1} doesn\'t exist').format(
                path, name)
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(alternatives.set_(name, path), ret)
Пример #2
0
def test_set():
    """
    Test to sets alternative for <name> to <path>, if <path> is defined
    as an alternative for <name>.
    """
    name = "pager"
    path = "/usr/bin/less"

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

    mock = MagicMock(side_effect=[path, path, ""])
    mock_bool = MagicMock(return_value=True)
    mock_show = MagicMock(side_effect=[path, False, False, False, False])
    with patch.dict(
            alternatives.__salt__,
        {
            "alternatives.display": mock,
            "alternatives.show_current": mock_show,
            "alternatives.set": mock_bool,
        },
    ):
        comt = "Alternative for {} already set to {}".format(name, path)
        ret.update({"comment": comt})
        assert alternatives.set_(name, path) == ret

        comt = "Alternative for {} will be set to path /usr/bin/less".format(
            name)
        ret.update({"comment": comt, "result": None})
        with patch.dict(alternatives.__opts__, {"test": True}):
            assert alternatives.set_(name, path) == ret

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

        comt = "Alternative {} for {} doesn't exist".format(path, name)
        ret.update({"comment": comt, "result": False})
        assert alternatives.set_(name, path) == ret
Пример #3
0
    def test_set(self):
        '''
        Test to sets alternative for <name> to <path>, if <path> is defined
        as an alternative for <name>.
        '''
        name = 'pager'
        path = '/usr/bin/less'

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

        mock = MagicMock(side_effect=[path, path, ''])
        mock_bool = MagicMock(return_value=True)
        mock_show = MagicMock(side_effect=[path, False, False, False, False])
        with patch.dict(alternatives.__salt__,
                        {'alternatives.display': mock,
                         'alternatives.show_current': mock_show,
                         'alternatives.set': mock_bool}):
            comt = ('Alternative for {0} already set to {1}'.format(name, path))
            ret.update({'comment': comt})
            self.assertDictEqual(alternatives.set_(name, path), ret)

            comt = ('Alternative for {0} will be set to path False'
                   ).format(name)
            ret.update({'comment': comt, 'result': None})
            with patch.dict(alternatives.__opts__, {'test': True}):
                self.assertDictEqual(alternatives.set_(name, path), ret)

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

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