def setUp(self): self.tunnel = SIOWC() self.agi = FastAGIProtocol() self.agi.factory = MockFastAGIFactory() self.agi.makeConnection(FileWrapper(self.tunnel)) self.agi._setEnv(ENV) self.asterisk = MockAsterisk(self.agi)
class AGITestCase(unittest.TestCase): """ Test case for the FastAGI applications. Has FastAGI protocol and mock asterisk instances. """ def setUp(self): self.tunnel = SIOWC() self.agi = FastAGIProtocol() self.agi.factory = MockFastAGIFactory() self.agi.makeConnection(FileWrapper(self.tunnel)) self.agi._setEnv(ENV) self.asterisk = MockAsterisk(self.agi) def getCommandDF(self, command, result_line, args, kwargs): cmd = command.title().split() method = cmd[0].lower() + (''.join(cmd[1:]) if len(cmd) > 1 else '') if hasattr(self.agi, method): df = getattr(self.agi, method)(*args, **kwargs) self.agi.lineReceived('200 result=%s' % result_line) return df else: self.fail('Unknown protocol method: %r' % method) def assertCommandResponse(self, params, result_line, *args, **kwargs): return self.getCommandDF(params[0], result_line, args, kwargs ).addCallback(self.assertEqual, Command(*params)) def assertCommandException(self, params, result_line, forErrors=(AGICommandFailure,), *args, **kwargs): def onError(failure, forErrors): if failure.trap(*forErrors): pass else: self.fail('expected: %s' % forErrors) return self.getCommandDF(params[0], result_line, args, kwargs ).addErrback(onError, forErrors)