[Twisted-web] NEWBIE: Unittest hangs by deferred
   
    Bart Frackiewicz
     
    twisted-web@twistedmatrix.com
       
    Fri, 09 Jan 2004 16:21:55 +0100
    
    
  
Hi,
i am a newbie to Twisted, so it would be fine if you can help me to 
understand, what i am doing wrong. I have a Package twisted_rpc3, which 
has a class City:
### file: twisted_rpc.py ###
  def getCityId(self, args):
      return dbpool.runInteraction(self._searchCityByString, args)
  def _searchCityByString(self, txn, args):
      .. search in database with some tricks
      return result # a string
### endfile: twisted_rpc.py ###
When i run this from bash, this works as excepted.
### file: city.py ###
import twisted_rpc3
def printResult(res):
    print res
c = twisted_rpc3.City()
c.getCityId(('berlin', 'de')).addCallback(printResult)
reactor.callLater(2, reactor.stop)
reactor.run()
### endfile: city.py ###
For the unittest, i create following:
## file test_twisted_rpc3.py ###
from twisted.trial import unittest
class TestCaseCity(unittest.TestCase):
    def testObject(self):
      c = twisted_rpc3.City()
    def testGetCityId(self):
      c = twisted_rpc3.City()
      d = c.getCityId(('Berlin', 'de'))
      self.assertEquals(unittest.deferredResult(d, 5), 'de_berlin')
## endfile test_twisted_rpc3.py ###
After starting test ([~/twisted]$ trial test_twisted_rpc3) , i get an 
timeout error, and if i add print statements, i see that getCityId() was 
called, but _searchCityByString() never. Where is my mistake?
TIA, Bart