[Telepathy-commits] [telepathy-gabble/master] Update the IBB test from master

Marco Barisione marco at barisione.org
Tue Jan 6 08:41:32 PST 2009


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

diff --git a/tests/twisted/tubes/test-si-ibb-tubes.py b/tests/twisted/tubes/test-si-ibb-tubes.py
index 95fec19..62a53a7 100644
--- a/tests/twisted/tubes/test-si-ibb-tubes.py
+++ b/tests/twisted/tubes/test-si-ibb-tubes.py
@@ -8,16 +8,15 @@ 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
 from twisted.internet import reactor
 from twisted.words.protocols.jabber.client import IQ
 
-from gabbleconfig import HAVE_DBUS_TUBES
-
 NS_TUBES = 'http://telepathy.freedesktop.org/xmpp/tubes'
 NS_SI = 'http://jabber.org/protocol/si'
 NS_FEATURE_NEG = 'http://jabber.org/protocol/feature-neg'
@@ -185,10 +184,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 tube 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 tube caps
     presence = domish.Element(('jabber:client', 'presence'))
     presence['from'] = 'bob at localhost/Bob'
     presence['to'] = 'test at localhost/Resource'
@@ -209,6 +231,38 @@ 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.
+    # Gabble does not allow to offer a tube to him.
+    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, "")
+    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
@@ -231,10 +285,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',
@@ -311,12 +361,12 @@ 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, "")
 
     event = q.expect('stream-message')
     message = event.stanza
+    assert message['to'] == 'bob at localhost/Bob' # check the resource
     tube_nodes = xpath.queryForNodes('/message/tube[@xmlns="%s"]' % NS_TUBES,
         message)
     assert tube_nodes is not None
@@ -369,7 +419,6 @@ def test(q, bus, conn, stream):
     tube_props = tube_chan.GetAll(
             'org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT',
             dbus_interface='org.freedesktop.DBus.Properties')
-    print str(tube_props.get("Parameters"))
     assert tube_props.get("Parameters") == dbus.Dictionary(
             {dbus.String(u'foo'): dbus.String(u'bar')},
             signature=dbus.Signature('sv'))
@@ -399,6 +448,7 @@ def test(q, bus, conn, stream):
 
     event = q.expect('stream-message')
     message = event.stanza
+    assert message['to'] == 'bob at localhost/Bob' # check the resource
     tube_nodes = xpath.queryForNodes('/message/tube[@xmlns="%s"]' % NS_TUBES,
         message)
     assert tube_nodes is not None
@@ -569,9 +619,6 @@ def test(q, bus, conn, stream):
     binary = base64.b64decode(str(ibb_data))
     assert binary == 'hello, world'
 
-    if not HAVE_DBUS_TUBES:
-        return
-
     # have the fake client open the stream
     # New tube API
     iq = IQ(stream, 'set')
@@ -605,9 +652,6 @@ def test(q, bus, conn, stream):
     binary = base64.b64decode(str(ibb_data))
     assert binary == 'hello, new world'
 
-    if not HAVE_DBUS_TUBES:
-        return
-
     # OK, how about D-Bus?
     call_async(q, tubes_iface, 'OfferDBusTube',
         'com.example.TestCase', sample_parameters)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list