[Telepathy-commits] [telepathy-gabble/master] Extract recipient end of a d-tube test into functions

Will Thompson will.thompson at collabora.co.uk
Tue Feb 3 03:36:39 PST 2009


---
 tests/twisted/tubes/offer-private-dbus-tube-ibb.py |  123 ++++++++++---------
 1 files changed, 65 insertions(+), 58 deletions(-)

diff --git a/tests/twisted/tubes/offer-private-dbus-tube-ibb.py b/tests/twisted/tubes/offer-private-dbus-tube-ibb.py
index 1977679..32ff30b 100644
--- a/tests/twisted/tubes/offer-private-dbus-tube-ibb.py
+++ b/tests/twisted/tubes/offer-private-dbus-tube-ibb.py
@@ -74,54 +74,7 @@ def test(q, bus, conn, stream):
     offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle)
     offer_new_dbus_tube(q, bus, conn, stream, self_handle, alice_handle)
 
-def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle):
-    # request tubes channel (old API)
-    tubes_path = conn.RequestChannel('org.freedesktop.Telepathy.Channel.Type.Tubes',
-        HT_CONTACT, alice_handle, True)
-    tubes_chan = bus.get_object(conn.bus_name, tubes_path)
-    tubes_iface = dbus.Interface(tubes_chan, tp_name_prefix + '.Channel.Type.Tubes')
-    tubes_chan_iface = dbus.Interface(tubes_chan, tp_name_prefix + '.Channel')
-
-    # Exercise basic Channel Properties from spec 0.17.7
-    channel_props = tubes_chan.GetAll(
-            'org.freedesktop.Telepathy.Channel',
-            dbus_interface='org.freedesktop.DBus.Properties')
-    assert channel_props.get('TargetHandle') == alice_handle,\
-            (channel_props.get('TargetHandle'), alice_handle)
-    assert channel_props.get('TargetHandleType') == HT_CONTACT,\
-            channel_props.get('TargetHandleType')
-    assert channel_props.get('ChannelType') == \
-            'org.freedesktop.Telepathy.Channel.Type.Tubes',\
-            channel_props.get('ChannelType')
-    assert 'Interfaces' in channel_props, channel_props
-    assert channel_props['Interfaces'] == [], channel_props['Interfaces']
-    assert channel_props['TargetID'] == 'alice at localhost', channel_props['TargetID']
-    assert channel_props['Requested'] == True
-    assert channel_props['InitiatorID'] == 'test at localhost'
-    assert channel_props['InitiatorHandle'] == conn.GetSelfHandle()
-
-    # Offer a D-Bus tube using old API
-    call_async(q, tubes_iface, 'OfferDBusTube',
-            'com.example.TestCase', sample_parameters)
-
-    new_tube_event, iq_event, offer_return_event = \
-        q.expect_many(
-        EventPattern('dbus-signal', signal='NewTube'),
-        EventPattern('stream-iq', to='alice at localhost/Test'),
-        EventPattern('dbus-return', method='OfferDBusTube'))
-
-    # handle new_tube_event
-    dbus_tube_id = new_tube_event.args[0]
-    assert new_tube_event.args[1] == self_handle
-    assert new_tube_event.args[2] == 0       # DBUS
-    assert new_tube_event.args[3] == 'com.example.TestCase'
-    assert new_tube_event.args[4] == sample_parameters
-    assert new_tube_event.args[5] == TUBE_STATE_REMOTE_PENDING
-
-    # handle offer_return_event
-    assert offer_return_event.value[0] == dbus_tube_id
-
-    # handle SI iq
+def alice_accepts_tube(q, stream, iq_event, dbus_tube_id):
     iq = iq_event.stanza
 
     tube_nodes = xpath.queryForNodes('/iq/si/tube[@xmlns="%s"]'
@@ -145,12 +98,6 @@ def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle):
                       'u': ('uint', '123'),
                      }
 
-    tubes = tubes_iface.ListTubes(byte_arrays=True)
-    assert len(tubes) == 1
-    expected_tube = (dbus_tube_id, self_handle, TUBE_TYPE_DBUS,
-        'com.example.TestCase', sample_parameters, TUBE_STATE_REMOTE_PENDING)
-    check_tube_in_tubes(expected_tube, tubes)
-
     # Alice accepts the tube and wants to use IBB
     result = make_result_iq(stream, iq)
     result['from'] = 'alice at localhost/Test'
@@ -176,11 +123,9 @@ def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle):
     reply = make_result_iq(stream, iq)
     stream.send(reply)
 
-    q.expect('dbus-signal', signal='TubeStateChanged',
-        interface='org.freedesktop.Telepathy.Channel.Type.Tubes',
-        args=[dbus_tube_id, 2])
+    return dbus_stream_id
 
-    dbus_tube_adr = tubes_iface.GetDBusTubeAddress(dbus_tube_id)
+def send_dbus_message_to_alice(q, stream, dbus_tube_adr, dbus_stream_id):
     tube = Connection(dbus_tube_adr)
     signal = SignalMessage('/', 'foo.bar', 'baz')
     signal.append(42, signature='u')
@@ -206,6 +151,68 @@ def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle):
     # XXX: verify that it's actually in the "sender" slot, rather than just
     # being in the message somewhere
 
+def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle):
+    # request tubes channel (old API)
+    tubes_path = conn.RequestChannel('org.freedesktop.Telepathy.Channel.Type.Tubes',
+        HT_CONTACT, alice_handle, True)
+    tubes_chan = bus.get_object(conn.bus_name, tubes_path)
+    tubes_iface = dbus.Interface(tubes_chan, tp_name_prefix + '.Channel.Type.Tubes')
+    tubes_chan_iface = dbus.Interface(tubes_chan, tp_name_prefix + '.Channel')
+
+    # Exercise basic Channel Properties from spec 0.17.7
+    channel_props = tubes_chan.GetAll(
+            'org.freedesktop.Telepathy.Channel',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert channel_props.get('TargetHandle') == alice_handle,\
+            (channel_props.get('TargetHandle'), alice_handle)
+    assert channel_props.get('TargetHandleType') == HT_CONTACT,\
+            channel_props.get('TargetHandleType')
+    assert channel_props.get('ChannelType') == \
+            'org.freedesktop.Telepathy.Channel.Type.Tubes',\
+            channel_props.get('ChannelType')
+    assert 'Interfaces' in channel_props, channel_props
+    assert channel_props['Interfaces'] == [], channel_props['Interfaces']
+    assert channel_props['TargetID'] == 'alice at localhost', channel_props['TargetID']
+    assert channel_props['Requested'] == True
+    assert channel_props['InitiatorID'] == 'test at localhost'
+    assert channel_props['InitiatorHandle'] == conn.GetSelfHandle()
+
+    # Offer a D-Bus tube using old API
+    call_async(q, tubes_iface, 'OfferDBusTube',
+            'com.example.TestCase', sample_parameters)
+
+    new_tube_event, iq_event, offer_return_event = \
+        q.expect_many(
+        EventPattern('dbus-signal', signal='NewTube'),
+        EventPattern('stream-iq', to='alice at localhost/Test'),
+        EventPattern('dbus-return', method='OfferDBusTube'))
+
+    # handle new_tube_event
+    dbus_tube_id = new_tube_event.args[0]
+    assert new_tube_event.args[1] == self_handle
+    assert new_tube_event.args[2] == 0       # DBUS
+    assert new_tube_event.args[3] == 'com.example.TestCase'
+    assert new_tube_event.args[4] == sample_parameters
+    assert new_tube_event.args[5] == TUBE_STATE_REMOTE_PENDING
+
+    # handle offer_return_event
+    assert offer_return_event.value[0] == dbus_tube_id
+
+    tubes = tubes_iface.ListTubes(byte_arrays=True)
+    assert len(tubes) == 1
+    expected_tube = (dbus_tube_id, self_handle, TUBE_TYPE_DBUS,
+        'com.example.TestCase', sample_parameters, TUBE_STATE_REMOTE_PENDING)
+    check_tube_in_tubes(expected_tube, tubes)
+
+    dbus_stream_id = alice_accepts_tube(q, stream, iq_event, dbus_tube_id)
+
+    q.expect('dbus-signal', signal='TubeStateChanged',
+        interface='org.freedesktop.Telepathy.Channel.Type.Tubes',
+        args=[dbus_tube_id, 2])
+
+    dbus_tube_adr = tubes_iface.GetDBusTubeAddress(dbus_tube_id)
+    send_dbus_message_to_alice(q, stream, dbus_tube_adr, dbus_stream_id)
+
     # close the tube
     tubes_iface.CloseTube(dbus_tube_id)
     q.expect('dbus-signal', signal='TubeClosed', args=[dbus_tube_id])
-- 
1.5.6.5




More information about the telepathy-commits mailing list