def test_portNumber(self): """ L{SimpleResolverComplexifier} preserves the C{port} argument passed to C{resolveHostName} in its returned addresses. """ simple = SillyResolverSimple() complex = SimpleResolverComplexifier(simple) receiver = ResultHolder(self) complex.resolveHostName(receiver, u"example.com", 4321) self.assertEqual(receiver._started, True) self.assertEqual(receiver._ended, False) self.assertEqual(receiver._addresses, []) simple._requests[0].callback("192.168.1.1") self.assertEqual(receiver._addresses, [IPv4Address('TCP', '192.168.1.1', 4321)]) self.assertEqual(receiver._ended, True)
def test_failure(self): """ L{SimpleResolverComplexifier} translates a known error result from L{IResolverSimple.resolveHostName} into an empty result. """ simple = SillyResolverSimple() complex = SimpleResolverComplexifier(simple) receiver = ResultHolder(self) self.assertEqual(receiver._started, False) complex.resolveHostName(receiver, u"example.com") self.assertEqual(receiver._started, True) self.assertEqual(receiver._ended, False) self.assertEqual(receiver._addresses, []) simple._requests[0].errback(DNSLookupError("nope")) self.assertEqual(receiver._ended, True) self.assertEqual(receiver._addresses, [])
def test_success(self): """ L{SimpleResolverComplexifier} translates C{resolveHostName} into L{IResolutionReceiver.addressResolved}. """ simple = SillyResolverSimple() complex = SimpleResolverComplexifier(simple) receiver = ResultHolder(self) self.assertEqual(receiver._started, False) complex.resolveHostName(receiver, u"example.com") self.assertEqual(receiver._started, True) self.assertEqual(receiver._ended, False) self.assertEqual(receiver._addresses, []) simple._requests[0].callback("192.168.1.1") self.assertEqual(receiver._addresses, [IPv4Address('TCP', '192.168.1.1', 0)]) self.assertEqual(receiver._ended, True)
def test_error(self): """ L{SimpleResolverComplexifier} translates an unknown error result from L{IResolverSimple.resolveHostName} into an empty result and a logged error. """ simple = SillyResolverSimple() complex = SimpleResolverComplexifier(simple) receiver = ResultHolder(self) self.assertEqual(receiver._started, False) complex.resolveHostName(receiver, u"example.com") self.assertEqual(receiver._started, True) self.assertEqual(receiver._ended, False) self.assertEqual(receiver._addresses, []) simple._requests[0].errback(ZeroDivisionError("zow")) self.assertEqual(len(self.flushLoggedErrors(ZeroDivisionError)), 1) self.assertEqual(receiver._ended, True) self.assertEqual(receiver._addresses, [])