'Test that open channel packets cause a channel to be created and
opened or a failure message to be returned.'

def test_CHANNEL_OPEN(self):

    del self.transport.avatar
    self.conn.ssh_CHANNEL_OPEN((common.NS('TestChannel') + ('\x00\x00\x00\x01' * 4)))
    self.assertTrue(self.conn.channel.gotOpen)
    self.assertEqual(self.conn.channel.conn, self.conn)
    self.assertEqual(self.conn.channel.data, '\x00\x00\x00\x01')
    self.assertEqual(self.conn.channel.specificData, '\x00\x00\x00\x01')
    self.assertEqual(self.conn.channel.remoteWindowLeft, 1)
    self.assertEqual(self.conn.channel.remoteMaxPacket, 1)
    self.assertEqual(self.transport.packets, [(connection.MSG_CHANNEL_OPEN_CONFIRMATION, '\x00\x00\x00\x01\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x80\x00')])
    self.transport.packets = []
    self.conn.ssh_CHANNEL_OPEN((common.NS('BadChannel') + ('\x00\x00\x00\x02' * 4)))
    self.flushLoggedErrors()
    self.assertEqual(self.transport.packets, [(connection.MSG_CHANNEL_OPEN_FAILURE, (('\x00\x00\x00\x02\x00\x00\x00\x03' + common.NS('unknown    channel')) + common.NS('')))])
    self.transport.packets = []
    self.conn.ssh_CHANNEL_OPEN((common.NS('ErrorChannel') + ('\x00\x00\x00\x02' * 4)))
    self.flushLoggedErrors()
    self.assertEqual(self.transport.packets, [(connection.MSG_CHANNEL_OPEN_FAILURE, (('\x00\x00\x00\x02\x00\x00\x00\x02' + common.NS('unknown    failure')) + common.NS('')))])
