2
# Twisted, the Framework of Your Internet
3
# Copyright (C) 2001 Matthew W. Lefkowitz
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of version 2.1 of the GNU Lesser General Public
7
# License as published by the Free Software Foundation.
9
# This library is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
Test cases for twisted.names.
23
from pyunit import unittest
25
from twisted.names import dns
26
from twisted.internet import main, udp
27
from twisted.protocols import protocol
30
class DNSFactory(protocol.ServerFactory):
35
self.boss = dns.DNSServerBoss()
38
class ServerDNSTestCase(unittest.TestCase):
39
"""Test cases for DNS server and client."""
42
# hack until moshez lets me set the port for queries
49
factory = DNSFactory()
50
factory.boss.addDomain("example.foo", dns.SimpleDomain("example.foo", "1.1.1.1"))
51
p = udp.Port(2053, factory)
56
resolver = dns.Resolver(["localhost"])
57
d = resolver.resolve("example.foo")
58
d.addCallback(self.tS_result).addErrback(self.tS_error)
61
while not hasattr(self, "gotAnswer"):
67
def tS_result(self, result):
68
self.assertEquals(result, "1.1.1.1")
71
def tS_error(self, error):
72
raise RuntimeError, error
75
class LookupDNSTestCase(unittest.TestCase):
79
self.resolver = dns.Resolver(["207.19.98.16"])
81
def _testLookup(self, domain, type, result):
82
d = self.resolver.resolve(domain, type)
83
d.addCallback(self._result).addErrback(self._error)
85
while len(self.results) == 0:
87
self.assertEquals(self.results[0], result)
89
def _result(self, result):
90
self.results.append(result)
92
def _error(self, error):
93
raise RuntimeError, error
96
self._testLookup("zoteca.com", 1, "209.163.251.206")
99
self._testLookup("zoteca.com", 15, ['israel2.maxnm.com', 'www.maxnm.com'])