[Telepathy-commits] [telepathy-gabble/master] factor out send_reply_to_activity_view_request

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


20080703123508-7fe3f-fe22e91093094e78a3d8fb868cac3716717c0fe9.gz
---
 tests/twisted/olpc/olpc-activity-search.py |   36 +++++--------------------
 tests/twisted/olpc/util.py                 |   40 ++++++++++++++-------------
 2 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index bd8a84c..e52b101 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -10,7 +10,7 @@ from gabbletest import exec_test, make_result_iq, acknowledge_iq, sync_stream
 from twisted.words.xish import domish, xpath
 from twisted.words.protocols.jabber.client import IQ
 from util import announce_gadget, request_random_activity_view,\
-    answer_error_to_pubsub_request
+    answer_error_to_pubsub_request, send_reply_to_activity_view_request
 
 NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
 NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
@@ -127,20 +127,9 @@ def test(q, bus, conn, stream):
     assert property['name'] == 'color'
     assert property.children == ['#AABBCC,#001122']
 
-    # reply to request
-    reply = make_result_iq(stream, iq_event.stanza)
-    reply['from'] = 'gadget.localhost'
-    reply['to'] = 'alice at localhost'
-    view = xpath.queryForNodes('/iq/view', reply)[0]
-    activity = view.addElement((None, "activity"))
-    activity['room'] = 'room2 at conference.localhost'
-    activity['id'] = 'activity2'
-    properties = activity.addElement((NS_OLPC_ACTIVITY_PROPS, "properties"))
-    property = properties.addElement((None, "property"))
-    property['type'] = 'str'
-    property['name'] = 'color'
-    property.addContent('#AABBCC,#001122')
-    stream.send(reply)
+    send_reply_to_activity_view_request(stream, iq_event.stanza,
+            [('activity2', 'room2 at conference.localhost',
+                {'color': ('str', '#AABBCC,#001122')}, [])])
 
     ## Current views ##
     # view 0: activity 1 (with: Lucien, Jean)
@@ -181,20 +170,9 @@ def test(q, bus, conn, stream):
     assert (buddies[0]['jid'], buddies[1]['jid']) == ('alice at localhost',
             'bob at localhost')
 
-    # reply to request
-    reply = make_result_iq(stream, iq_event.stanza)
-    reply['from'] = 'gadget.localhost'
-    reply['to'] = 'alice at localhost'
-    view = xpath.queryForNodes('/iq/view', reply)[0]
-    activity = view.addElement((None, "activity"))
-    activity['room'] = 'room3 at conference.localhost'
-    activity['id'] = 'activity3'
-    properties = activity.addElement((NS_OLPC_ACTIVITY_PROPS, "properties"))
-    property = properties.addElement((None, "property"))
-    property['type'] = 'str'
-    property['name'] = 'color'
-    property.addContent('#AABBCC,#001122')
-    stream.send(reply)
+    send_reply_to_activity_view_request(stream, iq_event.stanza,
+            [('activity3', 'room3 at conference.localhost',
+                {'color': ('str', '#AABBCC,#001122')}, [])])
 
     ## Current views ##
     # view 0: activity 1 (with: Lucien, Jean)
diff --git a/tests/twisted/olpc/util.py b/tests/twisted/olpc/util.py
index 4ae6bb7..dccb56a 100644
--- a/tests/twisted/olpc/util.py
+++ b/tests/twisted/olpc/util.py
@@ -152,25 +152,8 @@ def send_gadget_current_activity_changed_msg(stream, buddy, view_id, id, room):
 
     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)
+def send_reply_to_activity_view_request(stream, stanza, activities):
+    reply = make_result_iq(stream, stanza)
     reply['from'] = 'gadget.localhost'
     reply['to'] = 'test at localhost'
     view = xpath.queryForNodes('/iq/view', reply)[0]
@@ -195,4 +178,23 @@ def request_random_activity_view(q, stream, conn, max, id, activities):
 
     stream.send(reply)
 
+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)
+
+    send_reply_to_activity_view_request(stream, iq_event.stanza, activities)
+
     return return_event.value[0]
-- 
1.5.6.5




More information about the Telepathy-commits mailing list