[Telepathy-commits] [telepathy-gabble/master] add olpc/olpc-activity-search.py
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:04 PDT 2008
20080521132159-7fe3f-6a97f73333e913420a4b2d1650b57feb332b01c4.gz
---
tests/twisted/Makefile.am | 1 +
tests/twisted/olpc/olpc-activity-search.py | 122 ++++++++++++++++++++++++++++
2 files changed, 123 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/olpc/olpc-activity-search.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index cc112c5..d52133f 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -5,6 +5,7 @@ TWISTED_TESTS = \
muc/test-muc-ownership.py \
muc/test-muc-properties.py \
muc/test-muc.py \
+ olpc/olpc-activity-search.py \
olpc/olpc-muc-invitation.py \
olpc/olpc-muc-prop-change.py \
olpc/test-olpc-bundle.py \
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
new file mode 100644
index 0000000..40b5b14
--- /dev/null
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -0,0 +1,122 @@
+"""
+test OLPC search activity
+"""
+
+import dbus
+
+from servicetest import call_async, EventPattern
+from gabbletest import exec_test, make_result_iq, acknowledge_iq
+
+from twisted.words.xish import domish, xpath
+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"
+NS_OLPC_CURRENT_ACTIVITY = "http://laptop.org/xmpp/current-activity"
+NS_OLPC_ACTIVITY_PROPS = "http://laptop.org/xmpp/activity-properties"
+NS_OLPC_BUDDY = "http://laptop.org/xmpp/buddy"
+NS_OLPC_ACTIVITY = "http://laptop.org/xmpp/activity"
+
+NS_PUBSUB = "http://jabber.org/protocol/pubsub"
+NS_DISCO_INFO = "http://jabber.org/protocol/disco#info"
+NS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items"
+
+
+NS_AMP = "http://jabber.org/protocol/amp"
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+
+ _, iq_event, disco_event = q.expect_many(
+ EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]),
+ EventPattern('stream-iq', to=None, query_ns='vcard-temp',
+ query_name='vCard'),
+ EventPattern('stream-iq', to='localhost', query_ns=NS_DISCO_ITEMS))
+
+ acknowledge_iq(stream, iq_event.stanza)
+
+ # announce Gadget service
+ reply = make_result_iq(stream, disco_event.stanza)
+ query = xpath.queryForNodes('/iq/query', reply)[0]
+ item = query.addElement((None, 'item'))
+ item['jid'] = 'gadget.localhost'
+ stream.send(reply)
+
+ # wait for Gadget disco#info query
+ event = q.expect('stream-iq', to='gadget.localhost', query_ns=NS_DISCO_INFO)
+ reply = make_result_iq(stream, event.stanza)
+ query = xpath.queryForNodes('/iq/query', reply)[0]
+ identity = query.addElement((None, 'identity'))
+ identity['category'] = 'collaboration'
+ identity['type'] = 'gadget'
+ identity['name'] = 'OLPC Gadget'
+ feature = query.addElement((None, 'feature'))
+ feature['var'] = NS_OLPC_BUDDY
+ feature = query.addElement((None, 'feature'))
+ feature['var'] = NS_OLPC_ACTIVITY
+ stream.send(reply)
+
+ activity_prop_iface = dbus.Interface(conn, 'org.laptop.Telepathy.ActivityProperties')
+ activity_iface = dbus.Interface(conn, 'org.laptop.Telepathy.Activity')
+
+ # FIXME: This is crack. We send this message so we can wait for the
+ # NewChannel signal and so be sure than Gabble handled the disco response.
+ message = domish.Element(('jabber:client', 'message'))
+ message['from'] = 'alice at localhost'
+ message['to'] = 'test at localhost'
+ message['type'] = 'chat'
+ body = message.addElement((None, 'body'))
+ body.addContent('hi!')
+ stream.send(message)
+ q.expect('dbus-signal', signal='NewChannel')
+
+ # request 3 random activities
+ call_async(q, activity_iface, 'RequestRandom', 3)
+
+ iq_event, return_event = q.expect_many(
+ EventPattern('stream-iq', to='gadget.localhost', query_ns=NS_OLPC_ACTIVITY),
+ EventPattern('dbus-return', method='RequestRandom'))
+
+ query = iq_event.stanza.firstChildElement()
+ assert query.name == 'query'
+ assert query['id'] == '0'
+ random = xpath.queryForNodes('/iq/query/random', iq_event.stanza)
+ assert len(random) == 1
+ assert random[0]['max'] == '3'
+
+ # reply to random query
+ reply = make_result_iq(stream, iq_event.stanza)
+ reply['from'] = 'gadget.localhost'
+ reply['to'] = 'alice at localhost'
+ query = xpath.queryForNodes('/iq/query', reply)[0]
+ activity = query.addElement((None, "activity"))
+ activity['room'] = 'room1 at conference.localhost'
+ properties = activity.addElement((NS_OLPC_ACTIVITY_PROPS, "properties"))
+ property = properties.addElement((None, "property"))
+ property['type'] = 'str'
+ property['name'] = 'color'
+ property.addContent('#005FE4,#00A0FF')
+ stream.send(reply)
+
+ view_path = return_event.value[0]
+ view0 = bus.get_object(conn.bus_name, view_path)
+ view0_iface = dbus.Interface(view0, 'org.laptop.Telepathy.ActivityView')
+
+ event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
+ handle, props = event.args
+ print handle
+ print props
+ assert conn.InspectHandles(2, [handle])[0] == 'room1 at conference.localhost'
+ assert props == {'color': '#005FE4,#00A0FF'}
+
+ # close view 0
+ call_async(q, view0_iface, 'Close')
+ event, _ = q.expect_many(
+ EventPattern('stream-message', to='gadget.localhost'),
+ EventPattern('dbus-return', method='Close'))
+ close = xpath.queryForNodes('/message/close', event.stanza)
+ assert len(close) == 1
+ assert close[0]['id'] == '0'
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the Telepathy-commits
mailing list