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 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)
class TestCall: "A fake Call object" def __init__(self, d, sip): self.d = d self.sip = sip def getLocalSIPAddress(self): return ('127.0.0.1', 5060) def getSTUNState(self): return False def startFakeInbound(self): from shtoom.sip import Dialog self.dialog = Dialog() self.dialog.setDirection(inbound=True) d = self.sip.app.acceptCall(call=self) d.addCallbacks(self.acceptedFakeCall, self.rejectedFakeCall).addErrback(log.err) 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 acceptedFakeCall(self, cookie): from shtoom.sdp import SDP, MediaDescription s = SDP() s.setServerIP('127.0.0.1') md = MediaDescription() s.addMediaDescription(md) md.setLocalPort(9876) if TDEBUG: print("accepted, got %r" % (cookie, )) self.cookie = cookie d, self.d = self.d, None self.sip.app.startCall(self.cookie, s, d.callback) def rejectedFakeCall(self, e): if TDEBUG: print("rejected, got %r" % (e, )) d, self.d = self.d, None d.errback(e) def dropCall(self): if TDEBUG: print("drop") self.sip.app.endCall(self.cookie) def terminateCall(self): if TDEBUG: print("remote end closed call") self.sip.app.endCall(self.cookie)
class TestCall: "A fake Call object" def __init__(self, d, sip): self.d = d self.sip = sip def getLocalSIPAddress(self): return ( '127.0.0.1', 5060) def getSTUNState(self): return False def startFakeInbound(self): from shtoom.sip import Dialog self.dialog = Dialog() self.dialog.setDirection(inbound=True) d = self.sip.app.acceptCall(call=self) d.addCallbacks(self.acceptedFakeCall, self.rejectedFakeCall).addErrback(log.err) 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 acceptedFakeCall(self, cookie): from shtoom.sdp import SDP, MediaDescription s = SDP() s.setServerIP('127.0.0.1') md = MediaDescription() s.addMediaDescription(md) md.setLocalPort(9876) if TDEBUG: print "accepted, got %r"%(cookie,) self.cookie = cookie d, self.d = self.d, None self.sip.app.startCall(self.cookie, s, d.callback) def rejectedFakeCall(self, e): if TDEBUG: print "rejected, got %r"%(e,) d, self.d = self.d, None d.errback(e) def dropCall(self): if TDEBUG: print "drop" self.sip.app.endCall(self.cookie) def terminateCall(self): if TDEBUG: print "remote end closed call" self.sip.app.endCall(self.cookie)
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',))
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 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', ))
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 testDialogCtor(self): from shtoom.sip import Dialog, Address ae = self.assertEquals 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)
class TestCall: "A fake Call object" def __init__(self, sip, uri=None): self.sip = sip self.uri = uri def startCall(self): self.d = defer.Deferred() return self.d def getLocalSIPAddress(self): return ( '127.0.0.1', 5060) def getSTUNState(self): return False 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 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 _cb_startFakeOutboundWithAuth(self, auth, uri): print("got auth", auth) d = self.sip.app.acceptCall(call=self) d.addCallbacks(self._cb_incomingCall, self.failedIncoming).addErrback(log.err) def _cb_incomingCall(self, response): from shtoom.exceptions import CallFailed if isinstance(response, CallFailed): return self.rejectedFakeCall(response) else: return self.acceptedFakeCall(response) def failedIncoming(self, failure): print("failed, got %r"%(failure,)) d, self.d = self.d, None d.errback(failure) return failure def acceptedFakeCall(self, cookie): print("accepted, got %r"%(cookie,)) from shtoom.rtp.formats import PT_PCMU, SDPGenerator from shtoom.exceptions import CallRejected self.cookie = cookie self.sip.app.selectDefaultFormat(self.cookie, sdp=None,fmts=[PT_PCMU,]) sdp = SDPGenerator().getSDP(self) d, self.d = self.d, None self.sip.app.startCall(self.cookie, sdp, d.callback) def rejectedFakeCall(self, response): print("rejected, got %r"%(response,)) d, self.d = self.d, None d.errback(response) def getVisibleAddress(self): return ('127.0.0.1', 9876) def dropCall(self): print("drop") if hasattr(self,'cookie'): self.sip.app.endCall(self.cookie) else: print("'cancelling' non-started call") self.sip.callEndedRestartChecking() def terminateCall(self): print("remote end closed call") self.sip.app.endCall(self.cookie) self.sip.callEndedRestartChecking()
class TestCall: "A fake Call object" def __init__(self, sip, uri=None): self.sip = sip self.uri = uri def startCall(self): self.d = defer.Deferred() return self.d def getLocalSIPAddress(self): return ( '127.0.0.1', 5060) def getSTUNState(self): return False 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 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 _cb_startFakeOutboundWithAuth(self, auth, uri): print "got auth", auth d = self.sip.app.acceptCall(call=self) d.addCallbacks(self._cb_incomingCall, self.failedIncoming).addErrback(log.err) def _cb_incomingCall(self, response): from shtoom.exceptions import CallFailed if isinstance(response, CallFailed): return self.rejectedFakeCall(response) else: return self.acceptedFakeCall(response) def failedIncoming(self, failure): print "failed, got %r"%(failure,) d, self.d = self.d, None d.errback(failure) return failure def acceptedFakeCall(self, cookie): print "accepted, got %r"%(cookie,) from shtoom.rtp.formats import PT_PCMU, SDPGenerator from shtoom.exceptions import CallRejected self.cookie = cookie self.sip.app.selectDefaultFormat(self.cookie, sdp=None,fmts=[PT_PCMU,]) sdp = SDPGenerator().getSDP(self) d, self.d = self.d, None self.sip.app.startCall(self.cookie, sdp, d.callback) def rejectedFakeCall(self, response): print "rejected, got %r"%(response,) d, self.d = self.d, None d.errback(response) def getVisibleAddress(self): return ('127.0.0.1', 9876) def dropCall(self): print "drop" if hasattr(self,'cookie'): self.sip.app.endCall(self.cookie) else: print "'cancelling' non-started call" self.sip.callEndedRestartChecking() def terminateCall(self): print "remote end closed call" self.sip.app.endCall(self.cookie) self.sip.callEndedRestartChecking()