示例#1
0
def test_absent():
    """
    Test to ensure that named value map is absent
    """
    name = "Server HP Health"
    ret = {"name": name, "result": False, "comment": "", "changes": {}}
    with patch.dict(zabbix_valuemap.__opts__, {"test": False}):
        with patch.dict(
                zabbix_valuemap.__salt__,
            {"zabbix.get_object_id_by_params": MagicMock(return_value=False)},
        ):
            ret["result"] = True
            ret["comment"] = 'Zabbix Value map "{}" does not exist.'.format(
                name)
            assert zabbix_valuemap.absent(name) == ret

        with patch.dict(
                zabbix_valuemap.__salt__,
            {"zabbix.get_object_id_by_params": MagicMock(return_value=11)},
        ):
            with patch.dict(
                    zabbix_valuemap.__salt__,
                {"zabbix.run_query": MagicMock(return_value=True)},
            ):
                ret["result"] = True
                ret["comment"] = 'Zabbix Value map "{}" deleted.'.format(name)
                ret["changes"] = {
                    name: {
                        "old": 'Zabbix Value map "{}" existed.'.format(name),
                        "new": 'Zabbix Value map "{}" deleted.'.format(name),
                    }
                }
                assert zabbix_valuemap.absent(name) == ret
示例#2
0
    def test_absent(self):
        '''
        Test to ensure that named value map is absent
        '''
        name = 'Server HP Health'
        ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
        with patch.dict(zabbix_valuemap.__opts__, {'test': False}):
            with patch.dict(zabbix_valuemap.__salt__, {
                    'zabbix.get_object_id_by_params':
                    MagicMock(return_value=False)
            }):
                ret['result'] = True
                ret['comment'] = 'Zabbix Value map "{0}" does not exist.'.format(
                    name)
                self.assertDictEqual(zabbix_valuemap.absent(name), ret)

            with patch.dict(
                    zabbix_valuemap.__salt__,
                {'zabbix.get_object_id_by_params': MagicMock(return_value=11)
                 }):
                with patch.dict(
                        zabbix_valuemap.__salt__,
                    {'zabbix.run_query': MagicMock(return_value=True)}):
                    ret['result'] = True
                    ret['comment'] = 'Zabbix Value map "{0}" deleted.'.format(
                        name)
                    ret['changes'] = {
                        name: {
                            'old':
                            'Zabbix Value map "{0}" existed.'.format(name),
                            'new':
                            'Zabbix Value map "{0}" deleted.'.format(name)
                        }
                    }
                    self.assertDictEqual(zabbix_valuemap.absent(name), ret)
示例#3
0
 def test_absent_test_mode(self):
     """
     Test to ensure that named value map is absent in test mode
     """
     name = "Server HP Health"
     ret = {"name": name, "result": False, "comment": "", "changes": {}}
     with patch.dict(zabbix_valuemap.__opts__, {"test": True}):
         with patch.dict(
                 zabbix_valuemap.__salt__,
             {"zabbix.get_object_id_by_params": MagicMock(return_value=11)},
         ):
             ret["result"] = True
             ret["comment"] = 'Zabbix Value map "{0}" would be deleted.'.format(
                 name)
             ret["changes"] = {
                 name: {
                     "old":
                     'Zabbix Value map "{0}" exists.'.format(name),
                     "new":
                     'Zabbix Value map "{0}" would be deleted.'.format(
                         name),
                 }
             }
             self.assertDictEqual(zabbix_valuemap.absent(name), ret)