def testProxyFd(self): self.proxy._poll = MockPoll() self.proxy._PrepareSockets() self.failUnless(isinstance(self.proxy._proxyfd, MockSocket)) self.assertEqual(list(self.proxy._fdmap.keys()), [1]) self.assertEqual(self.proxy._poll.registry, {1: select.POLLIN | select.POLLPRI | select.POLLERR})
def testPrepareSocketNoFds(self): self.server._poll = MockPoll() self.server._PrepareSockets() self.assertEqual(self.server._poll.registry, []) self.assertEqual(self.server._realauthfds, []) self.assertEqual(self.server._realacctfds, [])
def testIgnorePacketError(self): self.client.retries = 1 self.client.timeout = 1 self.client._socket = MockSocket(1, 2, six.b("valid reply")) self.client._poll = MockPoll() MockPoll.results = [(1, select.POLLIN)] packet = MockPacket(AccountingRequest, verify=True, error=True) self.assertRaises(Timeout, self.client._SendPacket, packet, 432)
def testValidReply(self): self.client.retries = 1 self.client.timeout = 1 self.client._socket = MockSocket(1, 2, six.b("valid reply")) self.client._poll = MockPoll() MockPoll.results = [(1, select.POLLIN)] packet = MockPacket(AccountingRequest, verify=True) reply = self.client._SendPacket(packet, 432) self.failUnless(reply is packet.reply)
def testPrepareSocketAcctFds(self): self.server._poll = MockPoll() self.server._fdmap = {} self.server.acctfds = [MockFd(12), MockFd(14)] self.server._PrepareSockets() self.assertEqual(list(self.server._fdmap.keys()), [12, 14]) self.assertEqual(self.server._poll.registry, [(12, select.POLLIN | select.POLLPRI | select.POLLERR), (14, select.POLLIN | select.POLLPRI | select.POLLERR)])
def testValidReply(self): # TODO: work out how to make test work for BSD if not hasattr(select, 'POLLIN'): return self.client.retries = 1 self.client.timeout = 1 self.client._socket = MockSocket(1, 2, six.b("valid reply")) self.client._poll = MockPoll() MockPoll.results = [(1, select.POLLIN)] packet = MockPacket(AccountingRequest, verify=True) reply = self.client._SendPacket(packet, 432) self.failUnless(reply is packet.reply)
def testPrepareSocketAuthFds(self): self.server._poll = MockPoll() self.server._fdmap = {} self.server.authfds = [MockFd(12), MockFd(14)] self.server._PrepareSockets() self.assertEqual(list(self.server._fdmap.keys()), [12, 14]) self.assertEqual( self.server._poll.registry, { 12: select.POLLIN | select.POLLPRI | select.POLLERR, 14: select.POLLIN | select.POLLPRI | select.POLLERR })
def testBindClosesSocket(self): s = MockSocket(socket.AF_INET, socket.SOCK_DGRAM) self.client._socket = s self.client._poll = MockPoll() self.client.bind((BIND_IP, BIND_PORT)) self.assertEqual(s.closed, True)