[Telepathy-commits] [telepathy-gabble/master] factor out request_random_activity_view to olpc/util.py

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


20080703104912-7fe3f-31aea7360cca23569cb6ccefac05d84918b8e60e.gz
---
 tests/twisted/olpc/current-activity.py |   31 +++-----------------------
 tests/twisted/olpc/util.py             |   37 ++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/tests/twisted/olpc/current-activity.py b/tests/twisted/olpc/current-activity.py
index 4f748b6..245d7c2 100644
--- a/tests/twisted/olpc/current-activity.py
+++ b/tests/twisted/olpc/current-activity.py
@@ -12,7 +12,7 @@ from twisted.words.xish import domish, xpath
 
 from util import announce_gadget, send_buddy_changed_current_act_msg,\
     answer_to_current_act_pubsub_request, answer_error_to_pubsub_request,\
-    send_gadget_current_activity_changed_msg
+    send_gadget_current_activity_changed_msg, request_random_activity_view
 
 NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
 NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
@@ -84,32 +84,9 @@ def test(q, bus, conn, stream):
 
     # request a activity view containing only Bob and one
     # activity in it.
-    call_async(q, gadget_iface, 'RequestRandomActivities', 1)
-
-    # TODO: would be cool to have to view test helper code
-    iq_event, return_event = q.expect_many(
-    EventPattern('stream-iq', to='gadget.localhost',
-        query_ns=NS_OLPC_ACTIVITY),
-    EventPattern('dbus-return', method='RequestRandomActivities'))
-
-    view = iq_event.stanza.firstChildElement()
-    assert view.name == 'view'
-    assert view['id'] == '0'
-    random = xpath.queryForNodes('/iq/view/random', iq_event.stanza)
-    assert len(random) == 1
-    assert random[0]['max'] == '1'
-
-    # reply to random query
-    reply = make_result_iq(stream, iq_event.stanza)
-    reply['from'] = 'gadget.localhost'
-    reply['to'] = 'test at localhost'
-    view = xpath.queryForNodes('/iq/view', reply)[0]
-    activity = view.addElement((None, "activity"))
-    activity['room'] = 'room3 at conference.localhost'
-    activity['id'] = 'activity3'
-    buddy = activity.addElement((None, 'buddy'))
-    buddy['jid'] = 'bob at localhost'
-    stream.send(reply)
+    request_random_activity_view(q, stream, conn, 1, '0',
+        [('activity3', 'room3 at conference.localhost', {},
+            [('bob at localhost', {}),]),])
 
     # Gadget sends us a current-activity change concerning a
     # known activity
diff --git a/tests/twisted/olpc/util.py b/tests/twisted/olpc/util.py
index 7b3efef..d5c7349 100644
--- a/tests/twisted/olpc/util.py
+++ b/tests/twisted/olpc/util.py
@@ -1,3 +1,6 @@
+import dbus
+
+from servicetest import call_async, EventPattern
 from gabbletest import make_result_iq, acknowledge_iq, elem, elem_iq
 from twisted.words.xish import domish, xpath
 from twisted.words.protocols.jabber.client import IQ
@@ -148,3 +151,37 @@ def send_gadget_current_activity_changed_msg(stream, buddy, view_id, id, room):
                     action='error')))
 
     stream.send(message)
+
+def request_random_activity_view(q, stream, conn, max, id, activities):
+    gadget_iface = dbus.Interface(conn, 'org.laptop.Telepathy.Gadget')
+
+    call_async(q, gadget_iface, 'RequestRandomActivities', max)
+
+    iq_event, return_event = q.expect_many(
+    EventPattern('stream-iq', to='gadget.localhost',
+        query_ns=NS_OLPC_ACTIVITY),
+    EventPattern('dbus-return', method='RequestRandomActivities'))
+
+    view = iq_event.stanza.firstChildElement()
+    assert view.name == 'view'
+    assert view['id'] == id
+    random = xpath.queryForNodes('/iq/view/random', iq_event.stanza)
+    assert len(random) == 1
+    assert random[0]['max'] == str(max)
+
+    # reply to random query
+    reply = make_result_iq(stream, iq_event.stanza)
+    reply['from'] = 'gadget.localhost'
+    reply['to'] = 'test at localhost'
+    view = xpath.queryForNodes('/iq/view', reply)[0]
+    for id, room, props, buddies in activities:
+        activity = view.addElement((None, "activity"))
+        activity['room'] = room
+        activity['id'] = id
+        # TODO: activity props
+        for jid, props in buddies:
+            # TODO: buddy props
+            buddy = activity.addElement((None, 'buddy'))
+            buddy['jid'] = jid
+
+    stream.send(reply)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list