[Telepathy-commits] [telepathy-gabble/master] olpc-buddy-search.py: update to use new test API

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:01:59 PDT 2008


20071212154038-7fe3f-15522bb646fb79cdd5b0fb839b954cd9e03809c5.gz
---
 tests/olpc-buddy-search.py |   71 ++++++++++++++++++-------------------------
 1 files changed, 30 insertions(+), 41 deletions(-)

diff --git a/tests/olpc-buddy-search.py b/tests/olpc-buddy-search.py
index e6c5bce..429b8d8 100644
--- a/tests/olpc-buddy-search.py
+++ b/tests/olpc-buddy-search.py
@@ -1,18 +1,14 @@
-"""test OLPC search buddy"""
-import base64
-import errno
-import os
+"""
+test OLPC search buddy
+"""
 
 import dbus
 
-# must come before the twisted imports due to side-effects
-from gabbletest import go, make_result_iq
-from servicetest import call_async, lazy, match, tp_name_prefix, unwrap, Event
+from servicetest import call_async, EventPattern
+from gabbletest import exec_test, make_result_iq, acknowledge_iq
 
-from twisted.internet.protocol import Factory, Protocol
-from twisted.words.protocols.jabber.client import IQ
 from twisted.words.xish import domish, xpath
-from twisted.internet import reactor
+from twisted.words.protocols.jabber.client import IQ
 
 NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
 NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
@@ -24,51 +20,48 @@ NS_PUBSUB = "http://jabber.org/protocol/pubsub"
 
 NS_AMP = "http://jabber.org/protocol/amp"
 
- at match('dbus-signal', signal='StatusChanged', args=[0, 1])
-def expect_connected(event, data):
-    data['buddy_info_iface'] = dbus.Interface(data['conn'],
-        'org.laptop.Telepathy.BuddyInfo')
+def test(q, bus, conn, stream):
+    conn.Connect()
+
+    _, iq_event = q.expect_many(
+        EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]),
+        EventPattern('stream-iq', to=None, query_ns='vcard-temp',
+            query_name='vCard'))
+
+    acknowledge_iq(stream, iq_event.stanza)
 
-    call_async(data['test'], data['conn_iface'], 'RequestHandles', 1,
-        ['bob at localhost'])
+    buddy_info_iface = dbus.Interface(conn, 'org.laptop.Telepathy.BuddyInfo')
 
-    return True
+    call_async(q, conn, 'RequestHandles', 1, ['bob at localhost'])
 
- at match('dbus-return', method='RequestHandles')
-def expect_request_handles_return(event, data):
+    event = q.expect('dbus-return', method='RequestHandles')
     handles = event.value[0]
     bob_handle = handles[0]
 
-    call_async(data['test'], data['buddy_info_iface'], 'GetProperties',
-            bob_handle)
+    call_async(q, buddy_info_iface, 'GetProperties', bob_handle)
 
-    return True
-
- at match('stream-iq', to='bob at localhost',
-    query_ns=NS_PUBSUB)
-def expect_get_buddy_info_pubsub_query(event, data):
+    # wait for pubsub query
+    event = q.expect('stream-iq', to='bob at localhost', query_ns=NS_PUBSUB)
     query = event.stanza
     assert query['to'] == 'bob at localhost'
 
     # send an error as reply
-    reply = IQ(data['stream'], 'error')
+    reply = IQ(stream, 'error')
     reply['id'] = query['id']
     reply['to'] = 'alice at localhost'
     reply['from'] = 'bob at localhost'
-    data['stream'].send(reply)
-
-    return True
+    stream.send(reply)
 
- at match('stream-iq', to='index.jabber.laptop.org',
-    query_ns=NS_OLPC_BUDDY)
-def expect_search_buddy_query(event, data):
+    # wait for buddy search query
+    event = q.expect('stream-iq', to='index.jabber.laptop.org',
+            query_ns=NS_OLPC_BUDDY)
     buddies = xpath.queryForNodes('/iq/query/buddy', event.stanza)
     assert len(buddies) == 1
     buddy = buddies[0]
     assert buddy['jid'] == 'bob at localhost'
 
     # send reply to the search query
-    reply = make_result_iq(data['stream'], event.stanza)
+    reply = make_result_iq('stream', event.stanza)
     reply['from'] = 'index.jabber.laptop.org'
     reply['to'] = 'alice at localhost'
     query = xpath.queryForNodes('/iq/query', reply)[0]
@@ -79,16 +72,12 @@ def expect_search_buddy_query(event, data):
     property['type'] = 'str'
     property['name'] = 'color'
     property.addContent('#005FE4,#00A0FF')
-    data['stream'].send(reply)
-
-    return True
+    stream.send(reply)
 
- at match('dbus-return', method='GetProperties')
-def expect_get_properties_return(event, data):
+    event = q.expect('dbus-return', method='GetProperties')
     props = event.value[0]
 
     assert props == {'color': '#005FE4,#00A0FF' }
-    return True
 
 if __name__ == '__main__':
-    go()
+    exec_test(test)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list