[Telepathy-commits] [telepathy-gabble/master] olpc/olpc-muc-invitation.py: use a dict to store handles

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Mon Sep 29 07:41:27 PDT 2008


---
 tests/twisted/olpc/olpc-muc-invitation.py |   44 +++++++++++++++--------------
 1 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/tests/twisted/olpc/olpc-muc-invitation.py b/tests/twisted/olpc/olpc-muc-invitation.py
index 9896ef3..acfa863 100644
--- a/tests/twisted/olpc/olpc-muc-invitation.py
+++ b/tests/twisted/olpc/olpc-muc-invitation.py
@@ -14,10 +14,11 @@ def test(q, bus, conn, stream):
 
     q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
 
-    bob_handle = conn.RequestHandles(1, ['bob at localhost'])[0]
+    handles = {}
+    handles['bob'] = conn.RequestHandles(1, ['bob at localhost'])[0]
 
     buddy_iface = dbus.Interface(conn, 'org.laptop.Telepathy.BuddyInfo')
-    call_async(q, buddy_iface, 'GetActivities', bob_handle)
+    call_async(q, buddy_iface, 'GetActivities', handles['bob'])
 
     event = q.expect('stream-iq', iq_type='get', to='bob at localhost')
     # Bob has no activities
@@ -50,13 +51,14 @@ def test(q, bus, conn, stream):
     stream.send(message)
 
     event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
-    chat_handle, props = event.args
+    handles['chat'], props = event.args
     assert props == {'color': '#ffff00,#00ffff', 'private' : True}
 
     event = q.expect('dbus-signal', signal='ActivitiesChanged')
-    bob_handle, acts = event.args
+    assert event.args[0] == handles['bob']
+    acts = event.args[1]
     assert len(acts) == 1
-    assert acts[0] == ('foo_id', chat_handle)
+    assert acts[0] == ('foo_id', handles['chat'])
 
     # Bobs invites us to the activity
     message = domish.Element((None, 'message'))
@@ -74,8 +76,7 @@ def test(q, bus, conn, stream):
     assert event.args[1] == 'org.freedesktop.Telepathy.Channel.Type.Text'
 
     assert event.args[2] == 2   # handle type
-    assert event.args[3] == 1   # handle
-    room_handle = 1
+    assert event.args[3] == handles['chat']   # handle
 
     text_chan = bus.get_object(conn.bus_name, event.args[0])
     group_iface = dbus.Interface(text_chan,
@@ -87,19 +88,18 @@ def test(q, bus, conn, stream):
 
     assert len(members) == 1
     assert conn.InspectHandles(1, members)[0] == 'bob at localhost'
-    bob_handle = members[0]
     assert len(local_pending) == 1
     # FIXME: the username-part-is-nickname assumption
     assert conn.InspectHandles(1, local_pending)[0] == \
             'chat at conf.localhost/test'
     assert len(remote_pending) == 0
 
-    room_self_handle = group_iface.GetSelfHandle()
-    assert room_self_handle == local_pending[0]
+    handles['chat_self'] = group_iface.GetSelfHandle()
+    assert handles['chat_self'] == local_pending[0]
 
     # by now, we should have picked up the extra activity properties
     buddy_iface = dbus.Interface(conn, 'org.laptop.Telepathy.BuddyInfo')
-    call_async(q, buddy_iface, 'GetActivities', bob_handle)
+    call_async(q, buddy_iface, 'GetActivities', handles['bob'])
 
     event = q.expect('stream-iq', iq_type='get', to='bob at localhost')
     # Bob still has no (public) activities
@@ -110,10 +110,10 @@ def test(q, bus, conn, stream):
 
     event = q.expect('dbus-return', method='GetActivities')
 
-    assert event.value == ([('foo_id', room_handle)],)
+    assert event.value == ([('foo_id', handles['chat'])],)
 
     # OK, now accept the invitation
-    call_async(q, group_iface, 'AddMembers', [room_self_handle], 'Oh, OK then')
+    call_async(q, group_iface, 'AddMembers', [handles['chat_self']], 'Oh, OK then')
 
     _, event, _ = q.expect_many(
         EventPattern('stream-presence', to='chat at conf.localhost/test'),
@@ -121,8 +121,8 @@ def test(q, bus, conn, stream):
         EventPattern('dbus-return', method='AddMembers')
         )
 
-    assert event.args == ['', [], [bob_handle], [],
-            [room_self_handle], 0, room_self_handle]
+    assert event.args == ['', [], [handles['bob']], [],
+            [handles['chat_self']], 0, handles['chat_self']]
 
     # Send presence for own membership of room.
     presence = domish.Element((None, 'presence'))
@@ -134,9 +134,9 @@ def test(q, bus, conn, stream):
     stream.send(presence)
 
     event = q.expect('dbus-signal', signal='MembersChanged')
-    assert event.args == ['', [room_self_handle], [], [], [], 0, 0]
+    assert event.args == ['', [handles['chat_self']], [], [], [], 0, 0]
 
-    call_async(q, buddy_iface, 'SetActivities', [('foo_id', room_handle)])
+    call_async(q, buddy_iface, 'SetActivities', [('foo_id', handles['chat'])])
 
     event = q.expect('stream-iq', iq_type='set')
     event.stanza['type'] = 'result'
@@ -147,17 +147,18 @@ def test(q, bus, conn, stream):
     q.expect('dbus-return', method='SetActivities')
     act_prop_iface = dbus.Interface(conn, 'org.laptop.Telepathy.ActivityProperties')
     call_async(q, act_prop_iface, 'SetProperties',
-        room_handle, {'color': '#ffff00,#00ffff', 'private': True})
+        handles['chat'], {'color': '#ffff00,#00ffff', 'private': True})
 
     event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
     chat_handle, props = event.args
+    assert chat_handle == handles['chat']
     assert props == {'color': '#ffff00,#00ffff', 'private' : True}
 
     q.expect('dbus-return', method='SetProperties')
     # Test sending an invitation
-    alice_handle = conn.RequestHandles(1,
+    handles['alice'] = conn.RequestHandles(1,
         ['alice at localhost'])[0]
-    call_async(q, group_iface, 'AddMembers', [alice_handle],
+    call_async(q, group_iface, 'AddMembers', [handles['alice']],
             'I want to test invitations')
 
     event = q.expect('stream-message', to='alice at localhost')
@@ -201,7 +202,7 @@ def test(q, bus, conn, stream):
     assert str(reasons[0]) == 'I want to test invitations'
 
     call_async(q, act_prop_iface, 'SetProperties',
-        room_handle, {'color': '#f00baa,#f00baa', 'private': True})
+        handles['chat'], {'color': '#f00baa,#f00baa', 'private': True})
 
     event = q.expect('stream-message', to='alice at localhost')
     message = event.stanza
@@ -230,6 +231,7 @@ def test(q, bus, conn, stream):
 
     event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
     chat_handle, props = event.args
+    assert chat_handle == handles['chat']
     assert props == {'color': '#f00baa,#f00baa', 'private' : True}
 
     q.expect('dbus-return', method='SetProperties')
-- 
1.5.6.5




More information about the Telepathy-commits mailing list