[telepathy-gabble/master] Port test-outgoing-call-rejected.py to JingleTest2
Will Thompson
will.thompson at collabora.co.uk
Thu Mar 26 08:16:14 PDT 2009
---
tests/twisted/jingle/jingletest2.py | 23 +++++++
.../twisted/jingle/test-outgoing-call-rejected.py | 70 ++++++--------------
2 files changed, 43 insertions(+), 50 deletions(-)
diff --git a/tests/twisted/jingle/jingletest2.py b/tests/twisted/jingle/jingletest2.py
index 7c85dcd..f82aa68 100644
--- a/tests/twisted/jingle/jingletest2.py
+++ b/tests/twisted/jingle/jingletest2.py
@@ -106,6 +106,9 @@ class JingleProtocol:
def match_jingle_action(self, q, action):
return q.name == 'jingle' and q['action'] == action
+ def extract_session_id(self, query):
+ return query['sid']
+
class GtalkProtocol03(JingleProtocol):
features = [ 'http://www.google.com/xmpp/protocol/voice/v1' ]
@@ -148,6 +151,9 @@ class GtalkProtocol03(JingleProtocol):
def TransportGoogleP2P(self):
return None
+ def extract_session_id(self, query):
+ return query['id']
+
class GtalkProtocol04(JingleProtocol):
features = [ 'http://www.google.com/xmpp/protocol/voice/v1',
'http://www.google.com/transport/p2p' ]
@@ -187,6 +193,8 @@ class GtalkProtocol04(JingleProtocol):
action = self._action_map(action)
return q.name == 'session' and q['type'] == action
+ def extract_session_id(self, query):
+ return query['id']
class JingleProtocol015(JingleProtocol):
features = [ 'http://www.google.com/transport/p2p',
@@ -311,6 +319,21 @@ class JingleTest2:
# Force Gabble to process the caps before doing any more Jingling
sync_stream(self.q, self.stream)
+ def set_sid_from_initiate(self, query):
+ self.sid = self.jp.extract_session_id(query)
+
+ def terminate(self, reason=None):
+ jp = self.jp
+
+ if reason is not None and jp.dialect == 'jingle-v0.31':
+ body = [("reason", None, {}, [(reason, None, {}, [])])]
+ else:
+ body = []
+
+ iq = jp.SetIq(self.peer, self.jid, [
+ jp.Jingle(self.sid, self.peer, 'session-terminate', body) ])
+ self.stream.send(jp.xml(iq))
+
def dbusify_codecs(self, codecs):
dbussed_codecs = [ (id, name, 0, rate, 0, {} )
for (name, id, rate) in codecs ]
diff --git a/tests/twisted/jingle/test-outgoing-call-rejected.py b/tests/twisted/jingle/test-outgoing-call-rejected.py
index f5d5317..e7c0ab2 100644
--- a/tests/twisted/jingle/test-outgoing-call-rejected.py
+++ b/tests/twisted/jingle/test-outgoing-call-rejected.py
@@ -1,54 +1,30 @@
-
"""
Test outgoing call handling. This tests the case when the
-remote party rejects our call.
+remote party rejects our call because they're busy.
"""
-from gabbletest import exec_test, make_result_iq, sync_stream
+from gabbletest import make_result_iq
from servicetest import make_channel_proxy, unwrap, tp_path_prefix
-import jingletest
-import gabbletest
-import dbus
-import time
-
-def test(q, bus, conn, stream):
- jt = jingletest.JingleTest(stream, 'test at localhost', 'foo at bar.com/Foo')
-
- # If we need to override remote caps, feats, codecs or caps,
- # this is a good time to do it
-
- # Connecting
- conn.Connect()
-
- q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
- q.expect('stream-authenticated')
- q.expect('dbus-signal', signal='PresenceUpdate',
- args=[{1L: (0L, {u'available': {}})}])
- q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
-
- # We need remote end's presence for capabilities
- jt.send_remote_presence()
+import constants as cs
- # Gabble doesn't trust it, so makes a disco
- event = q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info',
- to='foo at bar.com/Foo')
+from jingletest2 import JingleTest2, test_all_dialects
- jt.send_remote_disco_reply(event.stanza)
+def test(jp, q, bus, conn, stream):
+ remote_jid = 'foo at bar.com/Foo'
+ jt = JingleTest2(jp, conn, q, stream, 'test at localhost', remote_jid)
- # Force Gabble to process the caps before calling RequestChannel
- sync_stream(q, stream)
+ jt.prepare()
- handle = conn.RequestHandles(1, [jt.remote_jid])[0]
+ self_handle = conn.GetSelfHandle()
+ remote_handle = conn.RequestHandles(cs.HT_CONTACT, [remote_jid])[0]
- path = conn.RequestChannel(
- 'org.freedesktop.Telepathy.Channel.Type.StreamedMedia',
- 1, handle, True)
+ path = conn.RequestChannel(cs.CHANNEL_TYPE_STREAMED_MEDIA,
+ cs.HT_CONTACT, remote_handle, True)
signalling_iface = make_channel_proxy(conn, path, 'Channel.Interface.MediaSignalling')
media_iface = make_channel_proxy(conn, path, 'Channel.Type.StreamedMedia')
-
- media_iface.RequestStreams(handle, [0]) # 0 == MEDIA_STREAM_TYPE_AUDIO
+ media_iface.RequestStreams(remote_handle, [cs.MEDIA_STREAM_TYPE_AUDIO])
# S-E gets notified about new session handler, and calls Ready on it
e = q.expect('dbus-signal', signal='NewSessionHandler')
@@ -64,25 +40,19 @@ def test(q, bus, conn, stream):
stream_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
stream_handler.Ready(jt.get_audio_codecs_dbus())
- stream_handler.StreamState(2)
-
- e = q.expect('stream-iq')
- assert e.query.name == 'jingle'
- assert e.query['action'] == 'session-initiate'
- stream.send(gabbletest.make_result_iq(stream, e.stanza))
+ stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
- jt.outgoing_call_reply(e.query['sid'], False)
+ e = q.expect('stream-iq', predicate=lambda e:
+ jp.match_jingle_action(e.query, 'session-initiate'))
+ stream.send(make_result_iq(stream, e.stanza))
- # Test completed, close the connection
+ jt.set_sid_from_initiate(e.query)
+ jt.terminate(reason="busy")
e = q.expect('dbus-signal', signal='Close') #XXX - match against the path
conn.Disconnect()
q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
- return True
-
-
if __name__ == '__main__':
- exec_test(test)
-
+ test_all_dialects(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list