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
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)
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)
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)