def test_present_exists(self): """ Test to ensure that named action is present and not changed """ name = "Auto registration Databases" ret = {"name": name, "result": False, "comment": "", "changes": {}} with patch.dict(zabbix_action.__opts__, {"test": False}): with patch.dict( zabbix_action.__salt__, { "zabbix.get_zabbix_id_mapper": MagicMock(return_value={"action": "actionid"}), "zabbix.substitute_params": MagicMock(side_effect=[INPUT_PARAMS, EXISTING_OBJ]), "zabbix.run_query": MagicMock(return_value=["length of result is 1"]), "zabbix.compare_params": MagicMock(return_value={}), }, ): ret["result"] = True ret["comment"] = 'Zabbix Action "{0}" already exists and corresponds to a definition.'.format( name) self.assertDictEqual(zabbix_action.present(name, {}), ret)
def test_present_update(self): """ Test to ensure that named action is present but must be updated """ name = "Auto registration Databases" ret = {"name": name, "result": False, "comment": "", "changes": {}} def side_effect_run_query(*args): """ Differentiate between __salt__ exec module function calls with different parameters. """ if args[0] == "action.get": return ["length of result is 1 = action exists"] elif args[0] == "action.update": return DIFF_PARAMS with patch.dict(zabbix_action.__opts__, {"test": False}): with patch.dict( zabbix_action.__salt__, { "zabbix.get_zabbix_id_mapper": MagicMock(return_value={"action": "actionid"}), "zabbix.substitute_params": MagicMock(side_effect=[INPUT_PARAMS, EXISTING_OBJ_DIFF]), "zabbix.run_query": MagicMock(side_effect=side_effect_run_query), "zabbix.compare_params": MagicMock(return_value=DIFF_PARAMS), }, ): ret["result"] = True ret["comment"] = 'Zabbix Action "{0}" updated.'.format(name) ret["changes"] = { name: { "old": 'Zabbix Action "{0}" differed ' "in following parameters: {1}".format( name, DIFF_PARAMS), "new": 'Zabbix Action "{0}" fixed.'.format(name), } } self.assertDictEqual(zabbix_action.present(name, {}), ret)
def test_present_update(self): ''' Test to ensure that named action is present but must be updated ''' name = 'Auto registration Databases' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} def side_effect_run_query(*args): ''' Differentiate between __salt__ exec module function calls with different parameters. ''' if args[0] == 'action.get': return ['length of result is 1 = action exists'] elif args[0] == 'action.update': return DIFF_PARAMS with patch.dict(zabbix_action.__opts__, {'test': False}): with patch.dict( zabbix_action.__salt__, { 'zabbix.get_zabbix_id_mapper': MagicMock(return_value={'action': 'actionid'}), 'zabbix.substitute_params': MagicMock(side_effect=[INPUT_PARAMS, EXISTING_OBJ_DIFF]), 'zabbix.run_query': MagicMock(side_effect=side_effect_run_query), 'zabbix.compare_params': MagicMock(return_value=DIFF_PARAMS) }): ret['result'] = True ret['comment'] = 'Zabbix Action "{0}" updated.'.format(name) ret['changes'] = { name: { 'old': 'Zabbix Action "{0}" differed ' 'in following parameters: {1}'.format( name, DIFF_PARAMS), 'new': 'Zabbix Action "{0}" fixed.'.format(name) } } self.assertDictEqual(zabbix_action.present(name, {}), ret)
def test_present_create(self): """ Test to ensure that named action is created """ name = "Auto registration Databases" ret = {"name": name, "result": False, "comment": "", "changes": {}} def side_effect_run_query(*args): """ Differentiate between __salt__ exec module function calls with different parameters. """ if args[0] == "action.get": return False elif args[0] == "action.create": return True with patch.dict(zabbix_action.__opts__, {"test": False}): with patch.dict( zabbix_action.__salt__, { "zabbix.get_zabbix_id_mapper": MagicMock(return_value={"action": "actionid"}), "zabbix.substitute_params": MagicMock(side_effect=[INPUT_PARAMS, False]), "zabbix.run_query": MagicMock(side_effect=side_effect_run_query), "zabbix.compare_params": MagicMock(return_value={}), }, ): ret["result"] = True ret["comment"] = 'Zabbix Action "{0}" created.'.format(name) ret["changes"] = { name: { "old": 'Zabbix Action "{0}" did not exist.'.format(name), "new": 'Zabbix Action "{0}" created according definition.'. format(name), } } self.assertDictEqual(zabbix_action.present(name, {}), ret)
def test_present_create(self): ''' Test to ensure that named action is created ''' name = 'Auto registration Databases' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} def side_effect_run_query(*args): ''' Differentiate between __salt__ exec module function calls with different parameters. ''' if args[0] == 'action.get': return False elif args[0] == 'action.create': return True with patch.dict(zabbix_action.__opts__, {'test': False}): with patch.dict( zabbix_action.__salt__, { 'zabbix.get_zabbix_id_mapper': MagicMock(return_value={'action': 'actionid'}), 'zabbix.substitute_params': MagicMock(side_effect=[INPUT_PARAMS, False]), 'zabbix.run_query': MagicMock(side_effect=side_effect_run_query), 'zabbix.compare_params': MagicMock(return_value={}) }): ret['result'] = True ret['comment'] = 'Zabbix Action "{0}" created.'.format(name) ret['changes'] = { name: { 'old': 'Zabbix Action "{0}" did not exist.'.format(name), 'new': 'Zabbix Action "{0}" created according definition.'. format(name) } } self.assertDictEqual(zabbix_action.present(name, {}), ret)
def test_present_exists(self): ''' Test to ensure that named action is present and not changed ''' name = 'Auto registration Databases' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} with patch.dict(zabbix_action.__opts__, {'test': False}): with patch.dict( zabbix_action.__salt__, { 'zabbix.get_zabbix_id_mapper': MagicMock(return_value={'action': 'actionid'}), 'zabbix.substitute_params': MagicMock(side_effect=[INPUT_PARAMS, EXISTING_OBJ]), 'zabbix.run_query': MagicMock(return_value=['length of result is 1']), 'zabbix.compare_params': MagicMock(return_value={}) }): ret['result'] = True ret['comment'] = 'Zabbix Action "{0}" already exists and corresponds to a definition.'.format( name) self.assertDictEqual(zabbix_action.present(name, {}), ret)