Esempio n. 1
0
    def test_present(self):
        '''
        Test to ensure a search is present.
        '''
        name = 'API Error Search'

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

        mock = MagicMock(side_effect=[True, False, False, True])
        with patch.dict(splunk_search.__salt__, {
                'splunk_search.get': mock,
                'splunk_search.create': mock
        }):
            with patch.dict(splunk_search.__opts__, {'test': True}):
                comt = ("Would update {0}".format(name))
                ret.update({'comment': comt})
                self.assertDictEqual(splunk_search.present(name), ret)

                comt = ("Would create {0}".format(name))
                ret.update({'comment': comt})
                self.assertDictEqual(splunk_search.present(name), ret)

            with patch.dict(splunk_search.__opts__, {'test': False}):
                ret.update({
                    'comment': '',
                    'result': True,
                    'changes': {
                        'new': {},
                        'old': False
                    }
                })
                self.assertDictEqual(splunk_search.present(name), ret)
Esempio n. 2
0
def test_present():
    """
    Test to ensure a search is present.
    """
    name = "API Error Search"

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

    mock = MagicMock(side_effect=[True, False, False, True])
    with patch.dict(
            splunk_search.__salt__,
        {
            "splunk_search.get": mock,
            "splunk_search.create": mock
        },
    ):
        with patch.dict(splunk_search.__opts__, {"test": True}):
            comt = "Would update {}".format(name)
            ret.update({"comment": comt})
            assert splunk_search.present(name) == ret

            comt = "Would create {}".format(name)
            ret.update({"comment": comt})
            assert splunk_search.present(name) == ret

        with patch.dict(splunk_search.__opts__, {"test": False}):
            ret.update({
                "comment": "",
                "result": True,
                "changes": {
                    "new": {},
                    "old": False
                }
            })
            assert splunk_search.present(name) == ret
Esempio n. 3
0
    def test_present(self):
        """
        Test to ensure a search is present.
        """
        name = "API Error Search"

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

        mock = MagicMock(side_effect=[True, False, False, True])
        with patch.dict(splunk_search.__salt__, {"splunk_search.get": mock, "splunk_search.create": mock}):
            with patch.dict(splunk_search.__opts__, {"test": True}):
                comt = "Would update {0}".format(name)
                ret.update({"comment": comt})
                self.assertDictEqual(splunk_search.present(name), ret)

                comt = "Would create {0}".format(name)
                ret.update({"comment": comt})
                self.assertDictEqual(splunk_search.present(name), ret)

            with patch.dict(splunk_search.__opts__, {"test": False}):
                ret.update({"comment": "", "result": True, "changes": {"new": {}, "old": False}})
                self.assertDictEqual(splunk_search.present(name), ret)