Пример #1
0
 def test_logoffButton(self):
     """
     L{ShellServer._logoffButton} returns a L{Button} which, when activated,
     disconnects the terminal.
     """
     terminal = FakeTerminal()
     server = ShellServer(Store())
     server.makeConnection(terminal)
     server._logoffButton().onPress()
     self.assertTrue(terminal.disconnected)
Пример #2
0
 def test_reactivate(self):
     """
     L{ShellServer.reactivate} disconnects the protocol previously switched
     to, drops the reference to it, and redraws the main menu.
     """
     terminal = FakeTerminal()
     server = ShellServer(Store())
     server.makeConnection(terminal)
     server.switchTo(MockTerminalServerFactory())
     server.reactivate()
     self.assertIdentical(server._protocol, None)
Пример #3
0
 def test_keystrokeReceivedProtocol(self):
     """
     L{ShellServer.keystrokeReceived} delivers keystroke data to the
     protocol built by the factory which has been switched to.
     """
     factory = MockTerminalServerFactory()
     terminal = FakeTerminal()
     server = ShellServer(Store())
     server.makeConnection(terminal)
     server.switchTo(factory)
     server.keystrokeReceived(' ', ServerProtocol.ALT)
     self.assertEqual(factory.terminalProtocolInstance.keystrokes,
                      [(' ', ServerProtocol.ALT)])
Пример #4
0
 def test_switchTo(self):
     """
     L{ShellServer.switchTo} takes a L{ITerminalServerFactory} and uses it
     to create a new L{ITerminalProtocol} which it connects to a
     L{_ReturnToMenuWrapper}.  L{buildTerminalProtocol} is passed an
     L{IViewer}.
     """
     terminal = FakeTerminal()
     store = Store()
     # Put a login method into the store so it can have a role.  See #2665.
     LoginMethod(
         store=store,
         internal=True,
         protocol=u'*',
         verified=True,
         localpart=u'alice',
         domain=u'example.com',
         # Not really an account, but simpler...
         account=store)
     server = ShellServer(store)
     server.makeConnection(terminal)
     factory = MockTerminalServerFactory()
     server.switchTo(factory)
     self.assertIdentical(factory.shellViewer.roleIn(store),
                          getSelfRole(store))
     self.assertTrue(isinstance(server._protocol, MockTerminalProtocol))
     self.assertTrue(
         isinstance(server._protocol.terminal, _ReturnToMenuWrapper))
     self.assertIdentical(server._protocol.terminal._shell, server)
     self.assertIdentical(server._protocol.terminal._terminal, terminal)
Пример #5
0
 def test_reactivate(self):
     """
     L{ShellServer.reactivate} disconnects the protocol previously switched
     to, drops the reference to it, and redraws the main menu.
     """
     terminal = FakeTerminal()
     server = ShellServer(Store())
     server.makeConnection(terminal)
     server.switchTo(MockTerminalServerFactory())
     server.reactivate()
     self.assertIdentical(server._protocol, None)
Пример #6
0
 def test_switchTo(self):
     """
     L{ShellServer.switchTo} takes a L{ITerminalServerFactory} and uses it
     to create a new L{ITerminalProtocol} which it connects to a
     L{_ReturnToMenuWrapper}.  L{buildTerminalProtocol} is passed an
     L{IViewer}.
     """
     terminal = FakeTerminal()
     store = Store()
     # Put a login method into the store so it can have a role.  See #2665.
     LoginMethod(
         store=store, internal=True, protocol=u'*', verified=True,
         localpart=u'alice', domain=u'example.com',
         # Not really an account, but simpler...
         account=store)
     server = ShellServer(store)
     server.makeConnection(terminal)
     factory = MockTerminalServerFactory()
     server.switchTo(factory)
     self.assertIdentical(factory.shellViewer.roleIn(store), getSelfRole(store))
     self.assertTrue(isinstance(server._protocol, MockTerminalProtocol))
     self.assertTrue(isinstance(server._protocol.terminal, _ReturnToMenuWrapper))
     self.assertIdentical(server._protocol.terminal._shell, server)
     self.assertIdentical(server._protocol.terminal._terminal, terminal)
Пример #7
0
 def test_logoffButton(self):
     """
     L{ShellServer._logoffButton} returns a L{Button} which, when activated,
     disconnects the terminal.
     """
     terminal = FakeTerminal()
     server = ShellServer(Store())
     server.makeConnection(terminal)
     server._logoffButton().onPress()
     self.assertTrue(terminal.disconnected)
Пример #8
0
 def test_keystrokeReceivedProtocol(self):
     """
     L{ShellServer.keystrokeReceived} delivers keystroke data to the
     protocol built by the factory which has been switched to.
     """
     factory = MockTerminalServerFactory()
     terminal = FakeTerminal()
     server = ShellServer(Store())
     server.makeConnection(terminal)
     server.switchTo(factory)
     server.keystrokeReceived(' ', ServerProtocol.ALT)
     self.assertEqual(
         factory.terminalProtocolInstance.keystrokes,
         [(' ', ServerProtocol.ALT)])
Пример #9
0
    def test_appButtons(self):
        """
        L{ShellServer._appButtons} returns an iterator the elements of which
        are L{Button} instances, one for each L{ITerminalServerFactory}
        powerup.  When one of these buttons is activated, L{ShellServer} is
        switched to the corresponding L{ITerminalServerFactory}'s protocol.
        """
        store = Store()
        terminal = FakeTerminal()
        server = ShellServer(store)
        server.makeConnection(terminal)

        firstFactory = MockTerminalServerFactoryItem(
            store=store, name=u"first - \N{ROMAN NUMERAL ONE}")
        installOn(firstFactory, store)
        secondFactory = MockTerminalServerFactoryItem(
            store=store, name=u"second - \N{ROMAN NUMERAL TWO}")
        installOn(secondFactory, store)

        buttons = list(server._appButtons())
        self.assertEqual(len(buttons), 2)

        # For now, we'll say the order isn't significant.
        buttons.sort(key=lambda b: b.label)

        self.assertEqual(buttons[0].label, firstFactory.name.encode('utf-8'))
        buttons[0].onPress()

        server.keystrokeReceived('x', None)
        self.assertEqual(firstFactory.terminalProtocolInstance.keystrokes,
                         [('x', None)])

        self.assertEqual(buttons[1].label, secondFactory.name.encode('utf-8'))
        buttons[1].onPress()
        server.keystrokeReceived('y', None)
        self.assertEqual(secondFactory.terminalProtocolInstance.keystrokes,
                         [('y', None)])
Пример #10
0
    def test_appButtons(self):
        """
        L{ShellServer._appButtons} returns an iterator the elements of which
        are L{Button} instances, one for each L{ITerminalServerFactory}
        powerup.  When one of these buttons is activated, L{ShellServer} is
        switched to the corresponding L{ITerminalServerFactory}'s protocol.
        """
        store = Store()
        terminal = FakeTerminal()
        server = ShellServer(store)
        server.makeConnection(terminal)

        firstFactory = MockTerminalServerFactoryItem(
            store=store, name=u"first - \N{ROMAN NUMERAL ONE}")
        installOn(firstFactory, store)
        secondFactory = MockTerminalServerFactoryItem(
            store=store, name=u"second - \N{ROMAN NUMERAL TWO}")
        installOn(secondFactory, store)

        buttons = list(server._appButtons())
        self.assertEqual(len(buttons), 2)

        # For now, we'll say the order isn't significant.
        buttons.sort(key=lambda b: b.label)

        self.assertEqual(
            buttons[0].label, firstFactory.name.encode('utf-8'))
        buttons[0].onPress()

        server.keystrokeReceived('x', None)
        self.assertEqual(
            firstFactory.terminalProtocolInstance.keystrokes, [('x', None)])

        self.assertEqual(
            buttons[1].label, secondFactory.name.encode('utf-8'))
        buttons[1].onPress()
        server.keystrokeReceived('y', None)
        self.assertEqual(
            secondFactory.terminalProtocolInstance.keystrokes, [('y', None)])
Пример #11
0
    def test_keystrokeReceivedWindow(self):
        """
        L{ShellServer.keystrokeReceived} delivers keystroke data to the main
        menu widget when no protocol has been switched to.
        """
        class FakeWidget(object):
            def __init__(self):
                self.keystrokes = []

            def keystrokeReceived(self, keyID, modifier):
                self.keystrokes.append((keyID, modifier))

        terminal = FakeTerminal()
        window = FakeWidget()
        server = ShellServer(Store())
        server._makeWindow = lambda: window
        server.makeConnection(terminal)
        server.keystrokeReceived(' ', ServerProtocol.ALT)
        self.assertEqual(window.keystrokes, [(' ', ServerProtocol.ALT)])
Пример #12
0
    def test_keystrokeReceivedWindow(self):
        """
        L{ShellServer.keystrokeReceived} delivers keystroke data to the main
        menu widget when no protocol has been switched to.
        """
        class FakeWidget(object):
            def __init__(self):
                self.keystrokes = []

            def keystrokeReceived(self, keyID, modifier):
                self.keystrokes.append((keyID, modifier))

        terminal = FakeTerminal()
        window = FakeWidget()
        server = ShellServer(Store())
        server._makeWindow = lambda: window
        server.makeConnection(terminal)
        server.keystrokeReceived(' ', ServerProtocol.ALT)
        self.assertEqual(window.keystrokes, [(' ', ServerProtocol.ALT)])