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)])
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)])
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)])
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)])
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)])