[Telepathy-commits] [telepathy-gabble/master] test-si-tubes.py: Test to offer a stream tube to a contact that does not advertise the tube capability

Alban Crequy alban.crequy at collabora.co.uk
Tue Nov 11 07:59:46 PST 2008


---
 tests/twisted/tubes/test-si-tubes.py |   69 ++++++++++++++++++++++++++++++----
 1 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/tests/twisted/tubes/test-si-tubes.py b/tests/twisted/tubes/test-si-tubes.py
index 4a07f7d..9acc17a 100644
--- a/tests/twisted/tubes/test-si-tubes.py
+++ b/tests/twisted/tubes/test-si-tubes.py
@@ -8,8 +8,9 @@ import dbus
 from dbus.connection import Connection
 from dbus.lowlevel import SignalMessage
 
-from servicetest import call_async, EventPattern, tp_name_prefix, watch_tube_signals
-from gabbletest import exec_test, acknowledge_iq
+from servicetest import call_async, EventPattern, tp_name_prefix, \
+     watch_tube_signals, sync_dbus
+from gabbletest import exec_test, acknowledge_iq, sync_stream
 
 from twisted.words.xish import domish, xpath
 from twisted.internet.protocol import Factory, Protocol
@@ -184,10 +185,33 @@ def test(q, bus, conn, stream):
     roster = roster_event.stanza
     roster['type'] = 'result'
     item = roster_event.query.addElement('item')
-    item['jid'] = 'bob at localhost'
+    item['jid'] = 'bob at localhost' # Bob can do tubes
+    item['subscription'] = 'both'
+    item = roster_event.query.addElement('item')
+    item['jid'] = 'joe at localhost' # Joe cannot do tubes
     item['subscription'] = 'both'
     stream.send(roster)
 
+    # Send Joe presence is without caps
+    presence = domish.Element(('jabber:client', 'presence'))
+    presence['from'] = 'joe at localhost/Joe'
+    presence['to'] = 'test at localhost/Resource'
+    c = presence.addElement('c')
+    c['xmlns'] = 'http://jabber.org/protocol/caps'
+    c['node'] = 'http://example.com/IDontSupportTubes'
+    c['ver'] = '1.0'
+    stream.send(presence)
+
+    event = q.expect('stream-iq', iq_type='get',
+        query_ns='http://jabber.org/protocol/disco#info',
+        to='joe at localhost/Joe')
+    result = event.stanza
+    result['type'] = 'result'
+    assert event.query['node'] == \
+        'http://example.com/IDontSupportTubes#1.0'
+    stream.send(result)
+
+    # Send Bob presence and his caps
     presence = domish.Element(('jabber:client', 'presence'))
     presence['from'] = 'bob at localhost/Bob'
     presence['to'] = 'test at localhost/Resource'
@@ -208,6 +232,40 @@ def test(q, bus, conn, stream):
     feature['var'] = NS_TUBES
     stream.send(result)
 
+    # A tube request can be done only if the contact has tube capabilities
+    # Ensure that Joe and Bob's caps have been received
+    sync_stream(q, stream)
+
+    # new requestotron
+    requestotron = dbus.Interface(conn,
+            'org.freedesktop.Telepathy.Connection.Interface.Requests')
+
+    # Test tubes with Joe. Joe does not have tube capabilities.
+    # Should Gabble allow to offer a tube to him? For now, accept it.
+    joe_handle = conn.RequestHandles(1, ['joe at localhost'])[0]
+    call_async(q, conn, 'RequestChannel',
+            tp_name_prefix + '.Channel.Type.Tubes', 1, joe_handle, True);
+
+    ret, old_sig, new_sig = q.expect_many(
+        EventPattern('dbus-return', method='RequestChannel'),
+        EventPattern('dbus-signal', signal='NewChannel'),
+        EventPattern('dbus-signal', signal='NewChannels'),
+        )
+    joe_chan_path = ret.value[0]
+
+    joe_tubes_chan = bus.get_object(conn.bus_name, joe_chan_path)
+    joe_tubes_iface = dbus.Interface(joe_tubes_chan,
+        tp_name_prefix + '.Channel.Type.Tubes')
+    path = os.getcwd() + '/stream'
+    call_async(q, joe_tubes_iface, 'OfferStreamTube',
+        'echo', sample_parameters, 0, dbus.ByteArray(path), 0, "")
+
+    sync_dbus(bus, q, conn)
+    # event = q.expect('dbus-error', method='OfferStreamTube')
+
+    joe_tubes_chan.Close()
+
+    # Test tubes with Bob. Bob does not have tube capabilities.
     bob_handle = conn.RequestHandles(1, ['bob at localhost'])[0]
 
     # old requestotron
@@ -230,10 +288,6 @@ def test(q, bus, conn, stream):
 
     check_conn_properties(q, bus, conn, stream, [old_tubes_channel_properties])
 
-    # new requestotron
-    requestotron = dbus.Interface(conn,
-            'org.freedesktop.Telepathy.Connection.Interface.Requests')
-
     # Try to CreateChannel with unknown properties
     # Gabble must return an error
     call_async(q, requestotron, 'CreateChannel',
@@ -310,7 +364,6 @@ def test(q, bus, conn, stream):
             bob_handle, "bob at localhost")
 
     # Offer the tube, old API
-    path = os.getcwd() + '/stream'
     call_async(q, tubes_iface, 'OfferStreamTube',
         'echo', sample_parameters, 0, dbus.ByteArray(path), 0, "")
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list