Ejemplo n.º 1
0
    def setUp(self):
        self.tcpConnections = []
        self.clock = Clock()

        self.transport = None
        self.terminal = TerminalBuffer()
        self.terminal.makeConnection(self.transport)
        self.protocol = UserInterface()
        self.protocol.reactor = self
        self.protocol.makeConnection(self.terminal)
Ejemplo n.º 2
0
class UserInterfaceTests(TestCase):
    """
    Test that the TerminalProtocol in charge of the user's terminal behaves in
    a bunch of desirable ways.
    """
    def setUp(self):
        self.transport = None
        self.terminal = TerminalBuffer()
        self.terminal.makeConnection(self.transport)
        self.protocol = UserInterface()


    def test_initialState(self):
        """
        Test that immediately after a connection is established the screen is
        cleared and cursor display is disabled.
        """
        # Scribble on the terminal so we can tell that it gets cleared.
        self.terminal.write('test bytes')
        self.protocol.makeConnection(self.terminal)
        self.failUnless(str(self.terminal).isspace())
        self.failIfIn(privateModes.CURSOR_MODE, self.terminal.privateModes)
Ejemplo n.º 3
0
class InputParsingTests(TestCase):
    """
    Tests for dealing with user input which may contain commands or be a
    message destined for the network.
    """
    def setUp(self):
        self.tcpConnections = []
        self.clock = Clock()

        self.transport = None
        self.terminal = TerminalBuffer()
        self.terminal.makeConnection(self.transport)
        self.protocol = UserInterface()
        self.protocol.reactor = self
        self.protocol.makeConnection(self.terminal)


    def connectTCP(self, host, port, factory, timeout=30, bindAddress=''):
        self.tcpConnections.append((host, port, factory, timeout, bindAddress))


    def callLater(self, n, f, *a, **kw):
        return self.clock.callLater(n, f, *a, **kw)


    def test_commandDispatch(self):
        """
        Verify that a line starting with C{/} and a word is dispatched to a
        function determined by that word.
        """
        dispatched = []
        self.protocol.cmd_DISPATCHTEST = dispatched.append
        self.protocol.parseInputLine('/dispatchtest')
        self.assertEqual(dispatched, ['/dispatchtest'])


    def test_serverCommand(self):
        """
        Verify that C{/server} is interpreted as a command to establish a new
        server connection.  Also some more things (that a connection attempt is
        made, that when it succeeds an IRC login is attempted over it with the
        right nickname).

        This is poorly factored.  IRC testing should be done elsewhere.
        Connection setup testing should be done elsewhere.
        """
        # XXX See #2504 in Twisted tracker
        from twisted.words.im import ircsupport
        self.patch(ircsupport, 'reactor', self)

        self.protocol.cmd_SERVER('/server irc.example.org testuser')
        self.assertEqual(len(self.tcpConnections), 1)
        self.assertEqual(self.tcpConnections[0][:2], ('irc.example.org', 6667))
        factory = self.tcpConnections[0][2]
        protocol = factory.buildProtocol(('irc.example.org', 6667))
        transport = StringTransport()
        protocol.makeConnection(transport)

        while self.clock.calls:
            self.clock.advance(1)

        self.assertEqual(
            transport.value(),
            'NICK testuser\r\n'
            'USER testuser foo bar :Twisted-IM user\r\n')

        output = str(self.terminal).splitlines()
        input = output.pop()
        status = output.pop()
        report = output.pop()
        for L in output:
            self.assertEqual(L, ' ' * 80)
        message = '== Connection to irc.example.org established.'
        self.assertEqual(report, message + ' ' * (80 - len(message)))


    def test_serverCommandFailedConnection(self):
        """
        Like L{test_serverCommand} but for a connection which fails.
        """
        # XXX See #2504 in Twisted tracker
        from twisted.words.im import ircsupport
        self.patch(ircsupport, 'reactor', self)

        self.protocol.cmd_SERVER('/server irc.example.org testuser')
        self.assertEqual(len(self.tcpConnections), 1)
        self.assertEqual(self.tcpConnections[0][:2], ('irc.example.org', 6667))
        factory = self.tcpConnections[0][2]
        factory.clientConnectionFailed(None, TimeoutError("mock"))

        while self.clock.calls:
            self.clock.advance(1)

        output = str(self.terminal).splitlines()
        input = output.pop()
        status = output.pop()
        report = output.pop()
        for L in output:
            self.assertEqual(L, ' ' * 80)
        message = '== irc.example.org failed: User timeout caused connection failure: mock.'
        self.assertEqual(report, message + ' ' * (80 - len(message)))
Ejemplo n.º 4
0
 def setUp(self):
     self.transport = None
     self.terminal = TerminalBuffer()
     self.terminal.makeConnection(self.transport)
     self.protocol = UserInterface()