Exemplo n.º 1
0
def test_call():
    """
    Test to invoke a pre-defined Python function with arguments
    specified in the state declaration.
    """
    name = "cmd.script"
    ret = {"name": name, "result": False, "changes": {}, "comment": ""}

    flag = None

    def func():
        """
        Mock func method
        """
        if flag:
            return {}
        else:
            return []

    with patch.dict(cmd.__grains__, {"shell": "shell"}):
        flag = True
        assert cmd.call(name, func) == ret

        flag = False
        ret.update({"comment": "", "result": False, "changes": {"retval": []}})
        assert cmd.call(name, func) == ret
Exemplo n.º 2
0
    def test_call(self):
        '''
        Test to invoke a pre-defined Python function with arguments
        specified in the state declaration.
        '''
        name = 'cmd.script'
        #         func = 'myfunc'

        ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}

        flag = None

        def func():
            '''
            Mock func method
            '''
            if flag:
                return {}
            else:
                return []

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            flag = True
            self.assertDictEqual(cmd.call(name, func), ret)

            flag = False
            comt = ('onlyif condition is false')
            ret.update({
                'comment': '',
                'result': False,
                'changes': {
                    'retval': []
                }
            })
            self.assertDictEqual(cmd.call(name, func), ret)

            mock = MagicMock(return_value=1)
            with patch.dict(cmd.__salt__, {'cmd.retcode': mock}):
                with patch.dict(cmd.__opts__, {'test': True}):
                    comt = ('onlyif condition is false')
                    ret.update({
                        'comment': comt,
                        'skip_watch': True,
                        'result': True,
                        'changes': {}
                    })
                    self.assertDictEqual(cmd.call(name, func, onlyif=''), ret)
Exemplo n.º 3
0
    def test_call(self):
        """
        Test to invoke a pre-defined Python function with arguments
        specified in the state declaration.
        """
        name = "cmd.script"
        #         func = 'myfunc'

        ret = {"name": name, "result": False, "changes": {}, "comment": ""}

        flag = None

        def func():
            """
            Mock func method
            """
            if flag:
                return {}
            else:
                return []

        with patch.dict(cmd.__grains__, {"shell": "shell"}):
            flag = True
            self.assertDictEqual(cmd.call(name, func), ret)

            flag = False
            comt = "onlyif condition is false"
            ret.update({
                "comment": "",
                "result": False,
                "changes": {
                    "retval": []
                }
            })
            self.assertDictEqual(cmd.call(name, func), ret)

            mock = MagicMock(return_value=1)
            with patch.dict(cmd.__salt__, {"cmd.retcode": mock}):
                with patch.dict(cmd.__opts__, {"test": True}):
                    comt = "onlyif condition is false"
                    ret.update({
                        "comment": comt,
                        "skip_watch": True,
                        "result": True,
                        "changes": {},
                    })
                    self.assertDictEqual(cmd.call(name, func, onlyif=""), ret)
Exemplo n.º 4
0
    def test_call(self):
        '''
        Test to invoke a pre-defined Python function with arguments
        specified in the state declaration.
        '''
        name = 'cmd.script'
#         func = 'myfunc'

        ret = {'name': name,
               'result': False,
               'changes': {},
               'comment': ''}

        flag = None

        def func():
            '''
            Mock func method
            '''
            if flag:
                return {}
            else:
                return []

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            flag = True
            self.assertDictEqual(cmd.call(name, func), ret)

            flag = False
            comt = ('onlyif execution failed')
            ret.update({'comment': '', 'result': False,
                        'changes': {'retval': []}})
            self.assertDictEqual(cmd.call(name, func), ret)

            mock = MagicMock(return_value=1)
            with patch.dict(cmd.__salt__, {'cmd.retcode': mock}):
                with patch.dict(cmd.__opts__, {'test': True}):
                    comt = ('onlyif execution failed')
                    ret.update({'comment': comt, 'skip_watch': True,
                                'result': True, 'changes': {}})
                    self.assertDictEqual(cmd.call(name, func, onlyif=''), ret)