Пример #1
0
def test_value_update_test():
    """
    Test for value_present test=True
    """

    name = "testfile.xml"
    xpath = ".//list[@id='1']"
    value = "test value"

    old_value = "not test value"

    state_return = {
        "name": name,
        "changes": {
            name: {
                "old": old_value,
                "new": value
            }
        },
        "result": None,
        "comment": "{} will be updated".format(name),
    }

    with patch.dict(xml.__salt__,
                    {"xml.get_value": MagicMock(return_value=old_value)}):
        assert xml.value_present(name, xpath, value, test=True) == state_return
Пример #2
0
    def test_value_update_test(self):
        '''
        Test for value_present test=True
        '''

        name = "testfile.xml"
        xpath = ".//list[@id='1']"
        value = "test value"

        old_value = "not test value"

        state_return = {
            'name': name,
            'changes': {
                name: {
                    'old': old_value,
                    'new': value
                }
            },
            'result': None,
            'comment': '{0} will be updated'.format(name)
        }

        with patch.dict(xml.__salt__,
                        {'xml.get_value': MagicMock(return_value=old_value)}):
            self.assertDictEqual(
                xml.value_present(name, xpath, value, test=True), state_return)
Пример #3
0
    def test_value_update_invalid_xpath(self):
        '''
        Test for value_present invalid xpath
        '''

        name = "testfile.xml"
        xpath = ".//list[@id='1']"
        value = "test value"

        state_return = {
            'name': name,
            'changes': {},
            'result': False,
            'comment': 'xpath query {0} not found in {1}'.format(xpath, name)
            }

        with patch.dict(xml.__salt__, {'xml.get_value': MagicMock(return_value=False)}):
            self.assertDictEqual(xml.value_present(name, xpath, value, test=True), state_return)
Пример #4
0
    def test_value_already_present(self):
        '''
        Test for existing value_present
        '''

        name = "testfile.xml"
        xpath = ".//list[@id='1']"
        value = "test value"

        state_return = {
            'name': name,
            'changes': {},
            'result': True,
            'comment': '{0} is already present'.format(value)
            }

        with patch.dict(xml.__salt__, {'xml.get_value': MagicMock(return_value=value)}):
            self.assertDictEqual(xml.value_present(name, xpath, value), state_return)
Пример #5
0
def test_value_update_invalid_xpath():
    """
    Test for value_present invalid xpath
    """

    name = "testfile.xml"
    xpath = ".//list[@id='1']"
    value = "test value"

    state_return = {
        "name": name,
        "changes": {},
        "result": False,
        "comment": "xpath query {} not found in {}".format(xpath, name),
    }

    with patch.dict(xml.__salt__,
                    {"xml.get_value": MagicMock(return_value=False)}):
        assert xml.value_present(name, xpath, value, test=True) == state_return
Пример #6
0
def test_value_already_present():
    """
    Test for existing value_present
    """

    name = "testfile.xml"
    xpath = ".//list[@id='1']"
    value = "test value"

    state_return = {
        "name": name,
        "changes": {},
        "result": True,
        "comment": "{} is already present".format(value),
    }

    with patch.dict(xml.__salt__,
                    {"xml.get_value": MagicMock(return_value=value)}):
        assert xml.value_present(name, xpath, value) == state_return