def test_dns_exists():
    """
    Test to configure the DNS server list in the specified interface
    """
    ret = {"name": "salt", "changes": {}, "result": False, "comment": ""}
    with patch.dict(win_dns_client.__opts__, {"test": False}):
        ret.update({
            "changes": {
                "Servers Added": [],
                "Servers Removed": [],
                "Servers Reordered": [],
            },
            "comment": "servers entry is not a list !",
        })
        assert win_dns_client.dns_exists("salt") == ret

        mock = MagicMock(return_value=[2, "salt"])
        with patch.dict(win_dns_client.__salt__,
                        {"win_dns_client.get_dns_servers": mock}):
            ret.update({
                "changes": {},
                "comment": repr([2, "salt"]) + " are already configured",
                "result": True,
            })
            assert win_dns_client.dns_exists("salt", [2, "salt"]) == ret

            mock = MagicMock(side_effect=[False, True, True])
            with patch.dict(win_dns_client.__salt__,
                            {"win_dns_client.add_dns": mock}):
                ret.update({
                    "comment": "Failed to add 1 as DNS server number 1",
                    "result": False,
                })
                assert win_dns_client.dns_exists("salt", [1, "salt"]) == ret

                mock = MagicMock(return_value=False)
                with patch.dict(win_dns_client.__salt__,
                                {"win_dns_client.rm_dns": mock}):
                    ret.update({
                        "changes": {
                            "Servers Added": ["a"],
                            "Servers Removed": [],
                            "Servers Reordered": [],
                        },
                        "comment":
                        "Failed to remove 2 from DNS server list",
                    })
                    assert win_dns_client.dns_exists("salt", ["a"], "a",
                                                     1) == ret

                ret.update({
                    "comment": "DNS Servers have been updated",
                    "result": True
                })
                assert win_dns_client.dns_exists("salt", ["a"]) == ret
Beispiel #2
0
    def test_dns_exists(self):
        '''
            Test to configure the DNS server list in the specified interface
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': False,
               'comment': ''}
        with patch.dict(win_dns_client.__opts__, {"test": False}):
            ret.update({'changes': {'Servers Added': [],
                                    'Servers Removed': [],
                                    'Servers Reordered': []},
                        'comment': 'servers entry is not a list !'})
            self.assertDictEqual(win_dns_client.dns_exists('salt'), ret)

            mock = MagicMock(return_value=[2, 'salt'])
            with patch.dict(win_dns_client.__salt__,
                            {'win_dns_client.get_dns_servers': mock}):
                ret.update({'changes': {}, 'comment': "[2, 'salt'] are already"
                            " configured", 'result': True})
                self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                               [2, 'salt']),
                                     ret)

                mock = MagicMock(side_effect=[False, True, True])
                with patch.dict(win_dns_client.__salt__,
                                {'win_dns_client.add_dns': mock}):
                    ret.update({'comment': 'Failed to add 1 as DNS'
                                ' server number 1', 'result': False})
                    self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                                   [1, 'salt']
                                                                   ), ret)

                    mock = MagicMock(return_value=False)
                    with patch.dict(win_dns_client.__salt__,
                                    {'win_dns_client.rm_dns': mock}):
                        ret.update({'changes': {'Servers Added': ['a'],
                                                'Servers Removed': [],
                                                'Servers Reordered': []},
                                    'comment': 'Failed to remove 2 from DNS'
                                    ' server list'})
                        self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                                       ['a'],
                                                                       'a',
                                                                       1),
                                             ret)

                    ret.update({'comment': 'DNS Servers have been updated',
                                'result': True})
                    self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                                   ['a']), ret)
Beispiel #3
0
    def test_dns_exists(self):
        '''
            Test to configure the DNS server list in the specified interface
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': False,
               'comment': ''}
        with patch.dict(win_dns_client.__opts__, {"test": False}):
            ret.update({'changes': {'Servers Added': [],
                                    'Servers Removed': [],
                                    'Servers Reordered': []},
                        'comment': 'servers entry is not a list !'})
            self.assertDictEqual(win_dns_client.dns_exists('salt'), ret)

            mock = MagicMock(return_value=[2, 'salt'])
            with patch.dict(win_dns_client.__salt__,
                            {'win_dns_client.get_dns_servers': mock}):
                ret.update({'changes': {}, 'comment': "[2, 'salt'] are already"
                            " configured", 'result': True})
                self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                               [2, 'salt']),
                                     ret)

                mock = MagicMock(side_effect=[False, True, True])
                with patch.dict(win_dns_client.__salt__,
                                {'win_dns_client.add_dns': mock}):
                    ret.update({'comment': 'Failed to add 1 as DNS'
                                ' server number 1', 'result': False})
                    self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                                   [1, 'salt']
                                                                   ), ret)

                    mock = MagicMock(return_value=False)
                    with patch.dict(win_dns_client.__salt__,
                                    {'win_dns_client.rm_dns': mock}):
                        ret.update({'changes': {'Servers Added': ['a'],
                                                'Servers Removed': [],
                                                'Servers Reordered': []},
                                    'comment': 'Failed to remove 2 from DNS'
                                    ' server list'})
                        self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                                       ['a'],
                                                                       'a',
                                                                       1),
                                             ret)

                    ret.update({'comment': 'DNS Servers have been updated',
                                'result': True})
                    self.assertDictEqual(win_dns_client.dns_exists('salt',
                                                                   ['a']), ret)