Exemplo n.º 1
0
class TestDoNothing(TestCase):
    """Tests for DoNothingSession."""

    def setUp(self):
        super(TestDoNothing, self).setUp()
        self.session = DoNothingSession(None)

    def test_getPtyIsANoOp(self):
        # getPty is called on the way to establishing a shell. Since we don't
        # give out shells, it should be a no-op. Raising an exception would
        # log an OOPS, so we won't do that.
        self.assertEqual(None, self.session.getPty(None, None, None))

    def test_openShellNotImplemented(self):
        # openShell closes the connection.
        protocol = MockProcessTransport('bash')
        self.session.openShell(protocol)
        self.assertEqual(
            [('writeExtended', connection.EXTENDED_DATA_STDERR,
              'No shells on this server.\r\n'),
             ('loseConnection',)],
            protocol.log)

    def test_windowChangedNotImplemented(self):
        # windowChanged raises a NotImplementedError. It doesn't matter what
        # we pass it.
        self.assertRaises(NotImplementedError,
                          self.session.windowChanged, None)

    def test_providesISession(self):
        # DoNothingSession must provide ISession.
        self.failUnless(ISession.providedBy(self.session),
                        "DoNothingSession doesn't implement ISession")

    def test_closedDoesNothing(self):
        # closed is a no-op.
        self.assertEqual(None, self.session.closed())

    def test_execCommandNotImplemented(self):
        # DoNothingSession.execCommand spawns the appropriate process.
        protocol = MockProcessTransport('bash')
        command = 'cat /etc/hostname'
        self.session.execCommand(protocol, command)
        self.assertEqual(
            [('writeExtended', connection.EXTENDED_DATA_STDERR,
              'Not allowed to execute commands on this server.\r\n'),
             ('loseConnection',)],
            protocol.log)

    def test_eofReceivedDoesNothingWhenNoCommand(self):
        # When no process has been created, 'eofReceived' is a no-op.
        self.assertEqual(None, self.session.eofReceived())
Exemplo n.º 2
0
class TestDoNothing(TestCase):
    """Tests for DoNothingSession."""
    def setUp(self):
        super(TestDoNothing, self).setUp()
        self.session = DoNothingSession(None)

    def test_getPtyIsANoOp(self):
        # getPty is called on the way to establishing a shell. Since we don't
        # give out shells, it should be a no-op. Raising an exception would
        # log an OOPS, so we won't do that.
        self.assertEqual(None, self.session.getPty(None, None, None))

    def test_openShellNotImplemented(self):
        # openShell closes the connection.
        protocol = MockProcessTransport('bash')
        self.session.openShell(protocol)
        self.assertEqual([('writeExtended', connection.EXTENDED_DATA_STDERR,
                           'No shells on this server.\r\n'),
                          ('loseConnection', )], protocol.log)

    def test_windowChangedNotImplemented(self):
        # windowChanged raises a NotImplementedError. It doesn't matter what
        # we pass it.
        self.assertRaises(NotImplementedError, self.session.windowChanged,
                          None)

    def test_providesISession(self):
        # DoNothingSession must provide ISession.
        self.failUnless(ISession.providedBy(self.session),
                        "DoNothingSession doesn't implement ISession")

    def test_closedDoesNothing(self):
        # closed is a no-op.
        self.assertEqual(None, self.session.closed())

    def test_execCommandNotImplemented(self):
        # DoNothingSession.execCommand spawns the appropriate process.
        protocol = MockProcessTransport('bash')
        command = 'cat /etc/hostname'
        self.session.execCommand(protocol, command)
        self.assertEqual(
            [('writeExtended', connection.EXTENDED_DATA_STDERR,
              'Not allowed to execute commands on this server.\r\n'),
             ('loseConnection', )], protocol.log)

    def test_eofReceivedDoesNothingWhenNoCommand(self):
        # When no process has been created, 'eofReceived' is a no-op.
        self.assertEqual(None, self.session.eofReceived())
Exemplo n.º 3
0
 def setUp(self):
     super(TestDoNothing, self).setUp()
     self.session = DoNothingSession(None)
Exemplo n.º 4
0
 def setUp(self):
     super(TestDoNothing, self).setUp()
     self.session = DoNothingSession(None)