[Twisted-Python] Conch Testing server and client

Anshul Singhle anshul.singhle at gmail.com
Fri Jul 1 09:41:33 EDT 2011


Ok, here goes :
The test code :

from twisted.trial import unittest
from twisted.internet import defer, protocol, reactor
class TestAccountStatus(unittest.TestCase):
     def setUp(self):
         ssh_server = Server()
         self.server = reactor.listenTCP(ssh_server.port,
                      ssh_server.application(),
                      interface=ssh_server.interface)
         return self.server
     def tearDown(self):
         server, self.server = self.server,None
         return server.stopListening()
     def test_1(self):
         def got_data(data):
             self.assertEquals(data,"a")
         d = protocol.ClientCreator(reactor,
SimpleTransport).connectTCP('localhost', self.server.getHost().port)
         d.addCallback(got_data)
         return d

The client code :
from twisted.conch.ssh import transport, userauth, connection, common, keys,
channel
from twisted.internet import defer, protocol, reactor
class SimpleTransport(transport.SSHClientTransport):
    def verifyHostKey(self, hostKey, fingerprint):
        print 'host key fingerprint: %s' % fingerprint
        return defer.succeed(1)

    def connectionSecure(self):
        self.requestService(
            SimpleUserAuth('webchick',
                SimpleConnection()))

class SimpleUserAuth(userauth.SSHUserAuthClient):
    def getPassword(self):
        print "Get Password called"
        return defer.succeed("Thai1mil3ahb")

When I run the test I expect :
  tests
  TestAccountStatus
    test_1 ... Get Password called

followed by some errors , but atleast this much should be printed if the
client code is being called properly.
Instead I get:

[FAIL]: tests.TestAccountStatus.test_1

Traceback (most recent call last):
  File "tests.py", line 92, in got_data
    self.assertEquals(data,"a")
twisted.trial.unittest.FailTest: not equal:
a = <tests.SimpleTransport instance at 0x1024aa128>
b = 'a'

Instead of running the client the deferred is just returning an instance of
the Client Transport used by me  (SimpleTransport). Any ideas why this is
happening? Is this becuse I'm not using a ClientFactory or am I using the
deferred all wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20110701/a5584c9b/attachment.htm 


More information about the Twisted-Python mailing list