コード例 #1
0
ファイル: test_dns.py プロジェクト: tschmittni/salt
    def test_gai(self):
        # wrong type
        self.assertRaises(ValueError, _lookup_gai, 'mockq', 'WRONG')

        # wrong
        with patch.object(socket, 'getaddrinfo', MagicMock(side_effect=socket.gaierror)):
            for rec_t in ('A', 'AAAA'):
                self.assertEqual(_lookup_gai('mockq', rec_t), False)

        # example returns from getaddrinfo
        right = {
            'A': [
                [(2, 3, 3, '', ('10.1.1.1', 0))],
                [(2, 3, 3, '', ('10.1.1.1', 0)),
                 (2, 3, 3, '', ('10.2.2.2', 0)),
                 (2, 3, 3, '', ('10.3.3.3', 0))]
            ],
            'AAAA': [
                [(10, 3, 3, '', ('2a00:a00:b01:c02:d03:e04:f05:111', 0, 0, 0))],
                [(10, 3, 3, '', ('2a00:a00:b01:c02:d03:e04:f05:111', 0, 0, 0)),
                 (10, 3, 3, '', ('2a00:a00:b01:c02:d03:e04:f05:222', 0, 0, 0)),
                 (10, 3, 3, '', ('2a00:a00:b01:c02:d03:e04:f05:333', 0, 0, 0))]
            ]
        }

        for rec_t, tests in right.items():
            with patch.object(socket, 'getaddrinfo', MagicMock(side_effect=tests)):
                for test_res in self.RESULTS[rec_t]:
                    self.assertEqual(
                        _lookup_gai('mockq', rec_t), test_res,
                        msg='Error parsing {0} returns'.format(rec_t)
                    )
コード例 #2
0
ファイル: test_dns.py プロジェクト: nicholasmhughes/salt
    def test_gai(self):
        # wrong type
        self.assertRaises(ValueError, _lookup_gai, "mockq", "WRONG")

        # wrong
        with patch.object(socket, "getaddrinfo",
                          MagicMock(side_effect=socket.gaierror)):
            for rec_t in ("A", "AAAA"):
                self.assertEqual(False, _lookup_gai("mockq", rec_t))

        # example returns from getaddrinfo
        right = {
            "A": [
                [(2, 3, 3, "", ("10.1.1.1", 0))],
                [
                    (2, 3, 3, "", ("10.1.1.1", 0)),
                    (2, 3, 3, "", ("10.2.2.2", 0)),
                    (2, 3, 3, "", ("10.3.3.3", 0)),
                ],
            ],
            "AAAA": [
                [(10, 3, 3, "", ("2a00:a00:b01:c02:d03:e04:f05:111", 0, 0, 0))
                 ],
                [
                    (10, 3, 3, "", ("2a00:a00:b01:c02:d03:e04:f05:111", 0, 0,
                                    0)),
                    (10, 3, 3, "", ("2a00:a00:b01:c02:d03:e04:f05:222", 0, 0,
                                    0)),
                    (10, 3, 3, "", ("2a00:a00:b01:c02:d03:e04:f05:333", 0, 0,
                                    0)),
                ],
            ],
        }

        for rec_t, tests in right.items():
            with patch.object(socket, "getaddrinfo",
                              MagicMock(side_effect=tests)):
                for test_res in self.RESULTS[rec_t]:
                    self.assertEqual(
                        _lookup_gai("mockq", rec_t),
                        test_res,
                        msg="Error parsing {} returns".format(rec_t),
                    )