def testDialogCtor(self): from shtoom.sip import Dialog, Address ae = self.assertEqual addr1 = '"anthony" <sip:[email protected]>;tag=03860126' addr2 = 'sip:96748002@gw2;tag=3409638C-1B50' Addr1 = Address(addr1) Addr2 = Address(addr2) d = Dialog() d.setCaller(addr1) d.setCallee(addr2) ae(d.getCaller().__class__, Address) ae(str(d.getCaller()), addr1) ae(str(d.getCallee()), addr2) d.setCaller(Addr1) d.setCallee(Addr2) ae(d.getCaller(), Addr1) ae(d.getCallee(), Addr2) d.setDirection(inbound=True) ae(d.getRemoteTag(), Addr1) ae(d.getLocalTag(), Addr2) d.setDirection(outbound=True) ae(d.getLocalTag(), Addr1) ae(d.getRemoteTag(), Addr2)
def startFakeOutbound(self, uri): from shtoom.sip import Dialog self.dialog = Dialog() self.dialog.setDirection(outbound=True) d = self.sip.app.acceptCall(call=self) d.addCallbacks(self.acceptedFakeCall, self.rejectedFakeCall).addErrback(log.err)
def startFakeInbound(self): from shtoom.sip import Dialog self.dialog = Dialog(caller=self.uri) self.dialog.setDirection(inbound=True) d = self.sip.app.acceptCall(call=self) d.addCallbacks(self._cb_incomingCall, self.failedIncoming).addErrback(log.err)
def test_legConstructor(self): from shtoom.sip import Dialog ae = self.assertEqual d = Dialog() cookie = 'NCookie' l = Leg(cookie, d) ae(l.getCookie(), cookie) ae(l.getDialog(), d) l.setCookie('foo') ae(l.getCookie(), 'foo') # We should be connected to silence at this point class Foo: def handle_media_sample(self, sample, tester=self): tester.fail("WRONG. We should be hearing silence, but we received this sample: %s" % (sample,)) l.set_handler(Foo())
def startFakeOutbound(self, uri): from shtoom.sip import Dialog self.dialog = Dialog() self.dialog.setDirection(outbound=True) if 'auth' in uri: # Any test calls to a URI containing the string 'auth' # trigger an auth dialog d = self.sip.app.authCred('INVITE', uri, realm='fake.realm.here') d.addCallback(self._cb_startFakeOutboundWithAuth, uri) if 'reject' in uri: # Any test calls to a URI containing the string 'reject' # will fail. d, self.d = self.d, None d.errback(CallFailed('rejected call')) else: d = self.sip.app.acceptCall(call=self) d.addCallbacks(self._cb_incomingCall, self.failedIncoming).addErrback(log.err)
def test_legCallSetup(self): from shtoom.sip import Dialog ae = self.assertEquals d = Dialog() cookie = 'NCookie' class A: res = None def good(self, res): self.res = res def bad(self, err): self.res = err l = Leg(cookie, d) a = A() d = defer.Deferred() d.addCallbacks(a.good, a.bad) l.incomingCall(d) ae(a.res, None) l.answerCall(voiceapp=None) twisted.trial.util.wait(d) ae(a.res, cookie) l.rejectCall(Exception('because')) twisted.trial.util.wait(d) ae(a.res, cookie) l = Leg(cookie, d) a = A() d = defer.Deferred() d.addCallbacks(a.good, a.bad) l.incomingCall(d) ae(a.res, None) # XXX should be an exception l.rejectCall(Exception('because')) twisted.trial.util.wait(d) # rejectCall triggers an errback, so we get # Failure(DefaultException(reason)) ae(a.res.value.args, ('because', ))