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 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 testGrabPacket(self): def gen(data): res = TrivialObject() res.data = data return res fd = MockFd() fd.source = object() pkt = self.server._GrabPacket(gen, fd) self.failUnless(isinstance(pkt, TrivialObject)) self.failUnless(pkt.fd is fd) self.failUnless(pkt.source is fd.source) self.failUnless(pkt.data is fd.data)
def testRunIgnoresPacketErrors(self): def RaisePacketError(self, fd): raise PacketError MockClassMethod(Server, '_ProcessInput', RaisePacketError) self.server.authfds = [MockFd()] MockPoll.results = [(0, select.POLLIN)] self.assertRaises(MockFinished, self.server.Run)
def testRunRunsProcessInput(self): MockClassMethod(Server, '_ProcessInput') self.server.authfds = fd = [MockFd()] MockPoll.results = [(0, select.POLLIN)] self.assertRaises(MockFinished, self.server.Run) self.assertEqual(self.server.called, [('_ProcessInput', (fd[0], ), {})])
def testAuthProcessInput(self): fd = MockFd(1) self.server._realauthfds = [1] MockClassMethod(Server, '_GrabPacket') MockClassMethod(Server, '_HandleAuthPacket') self.server._ProcessInput(fd) self.assertEqual([x[0] for x in self.server.called], ['_GrabPacket', '_HandleAuthPacket']) self.assertEqual(self.server.called[0][1][1], fd)
def testRunIgnoresPollErrors(self): self.server.authfds = [MockFd()] MockPoll.results = [(0, select.POLLERR)] self.assertRaises(MockFinished, self.server.Run)
def testProcessInputNonProxyPort(self): fd = MockFd(fd=111) MockClassMethod(Server, '_ProcessInput') self.proxy._ProcessInput(fd) self.assertEqual(self.proxy.called, [('_ProcessInput', (fd,), {})])
def setUp(self): self.proxy = Proxy() self.proxy._proxyfd = MockFd()