Esempio n. 1
0
    def test_update(self):
        '''
        Test to add, replace, or update a DNS record.
        '''
        mock_request = textwrap.dedent('''\
            id 29380
            opcode QUERY
            rcode NOERROR
            flags RD
            ;QUESTION
            name.zone. IN AAAA
            ;ANSWER
            ;AUTHORITY
            ;ADDITIONAL''')
        mock_rdtype = 28  # rdtype of AAAA record

        class MockRrset(object):
            def __init__(self):
                self.items = [{'address': 'localhost'}]
                self.ttl = 2

        class MockAnswer(object):
            def __init__(self, *args, **kwargs):
                self.answer = [MockRrset()]

            def rcode(self):
                return 0

        def mock_udp_query(*args, **kwargs):
            return MockAnswer

        if six.PY3:
            # pylint: disable=E0598
            with patch.object(dns.message, 'make_query', MagicMock(return_value=mock_request)), \
                    patch.object(dns.query, 'udp', mock_udp_query()), \
                    patch.object(dns.rdatatype, 'from_text', MagicMock(return_value=mock_rdtype)), \
                    patch.object(ddns, '_get_keyring', return_value=None), \
                    patch.object(ddns, '_config', return_value=None):
                self.assertTrue(ddns.update('zone', 'name', 1, 'AAAA', '::1'))
            # pylint: enable=E0598
        else:
            with contextlib.nested(
                    patch.object(dns.message, 'make_query',
                                 MagicMock(return_value=mock_request)),
                    patch.object(dns.query, 'udp', mock_udp_query()),
                    patch.object(dns.rdatatype, 'from_text',
                                 MagicMock(return_value=mock_rdtype)),
                    patch.object(ddns, '_get_keyring', return_value=None),
                    patch.object(ddns, '_config', return_value=None)):
                self.assertTrue(ddns.update('zone', 'name', 1, 'AAAA', '::1'))
Esempio n. 2
0
    def test_update(self):
        """
        Test to add, replace, or update a DNS record.
        """
        mock_request = textwrap.dedent(
            """\
            id 29380
            opcode QUERY
            rcode NOERROR
            flags RD
            ;QUESTION
            name.zone. IN AAAA
            ;ANSWER
            ;AUTHORITY
            ;ADDITIONAL"""
        )
        mock_rdtype = 28  # rdtype of AAAA record

        class MockRrset(object):
            def __init__(self):
                self.items = [{"address": "localhost"}]
                self.ttl = 2

        class MockAnswer(object):
            def __init__(self, *args, **kwargs):
                self.answer = [MockRrset()]

            def rcode(self):
                return 0

        def mock_udp_query(*args, **kwargs):
            return MockAnswer

        with patch.object(
            dns.message, "make_query", MagicMock(return_value=mock_request)
        ):
            with patch.object(dns.query, "udp", mock_udp_query()):
                with patch.object(
                    dns.rdatatype, "from_text", MagicMock(return_value=mock_rdtype)
                ):
                    with patch.object(ddns, "_get_keyring", return_value=None):
                        with patch.object(ddns, "_config", return_value=None):
                            self.assertTrue(
                                ddns.update("zone", "name", 1, "AAAA", "::1")
                            )
Esempio n. 3
0
    def test_update(self):
        '''
        Test to add, replace, or update a DNS record.
        '''
        mock_request = textwrap.dedent('''\
            id 29380
            opcode QUERY
            rcode NOERROR
            flags RD
            ;QUESTION
            name.zone. IN AAAA
            ;ANSWER
            ;AUTHORITY
            ;ADDITIONAL''')
        mock_rdtype = 28  # rdtype of AAAA record

        class MockRrset(object):
            def __init__(self):
                self.items = [{'address': 'localhost'}]
                self.ttl = 2

        class MockAnswer(object):
            def __init__(self, *args, **kwargs):
                self.answer = [MockRrset()]

            def rcode(self):
                return 0

        def mock_udp_query(*args, **kwargs):
            return MockAnswer

        with contextlib.nested(
                patch.object(dns.message, 'make_query', MagicMock(return_value=mock_request)),
                patch.object(dns.query, 'udp', mock_udp_query()),
                patch.object(dns.rdatatype, 'from_text', MagicMock(return_value=mock_rdtype)),
                patch.object(ddns, '_get_keyring', return_value=None),
                patch.object(ddns, '_config', return_value=None)):
            self.assertTrue(ddns.update('zone', 'name', 1, 'AAAA', '::1'))