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

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


20080703092439-7fe3f-b79990ea4a3e9b3877842f83cbe9dc8fe8514ab0.gz
---
 tests/twisted/olpc/current-activity.py |   43 ++++---------------------------
 tests/twisted/olpc/util.py             |   13 +++++++++
 2 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/tests/twisted/olpc/current-activity.py b/tests/twisted/olpc/current-activity.py
index e9b054f..4f748b6 100644
--- a/tests/twisted/olpc/current-activity.py
+++ b/tests/twisted/olpc/current-activity.py
@@ -11,7 +11,8 @@ from twisted.words.protocols.jabber.client import IQ
 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
+    answer_to_current_act_pubsub_request, answer_error_to_pubsub_request,\
+    send_gadget_current_activity_changed_msg
 
 NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
 NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
@@ -112,24 +113,8 @@ def test(q, bus, conn, stream):
 
     # Gadget sends us a current-activity change concerning a
     # known activity
-    message = domish.Element(('jabber:client', 'message'))
-    message['from'] = 'gadget.localhost'
-    message['to'] = 'alice at localhost'
-    message['type'] = 'notice'
-
-    change = message.addElement((NS_OLPC_BUDDY, 'change'))
-    change['jid'] = 'bob at localhost'
-    change['id'] = '0'
-    activity = change.addElement((NS_OLPC_CURRENT_ACTIVITY, 'activity'))
-    activity['type'] = 'activity3'
-    activity['room'] = 'room3 at conference.localhost'
-
-    amp = message.addElement((NS_AMP, 'amp'))
-    rule = amp.addElement((None, 'rule'))
-    rule['condition'] = 'deliver-at'
-    rule['value'] = 'stored'
-    rule['action'] ='error'
-    stream.send(message)
+    send_gadget_current_activity_changed_msg(stream, 'bob at localhost', '0',
+        'activity3', 'room3 at conference.localhost')
 
     # Gadget notifies us about the change
     event = q.expect('dbus-signal', signal='CurrentActivityChanged')
@@ -146,24 +131,8 @@ def test(q, bus, conn, stream):
 
     # Gadget sends us a current-activity change concerning an
     # unknown activity
-    message = domish.Element(('jabber:client', 'message'))
-    message['from'] = 'gadget.localhost'
-    message['to'] = 'alice at localhost'
-    message['type'] = 'notice'
-
-    change = message.addElement((NS_OLPC_BUDDY, 'change'))
-    change['jid'] = 'bob at localhost'
-    change['id'] = '0'
-    activity = change.addElement((NS_OLPC_CURRENT_ACTIVITY, 'activity'))
-    activity['type'] = 'activity4'
-    activity['room'] = 'room4 at conference.localhost'
-
-    amp = message.addElement((NS_AMP, 'amp'))
-    rule = amp.addElement((None, 'rule'))
-    rule['condition'] = 'deliver-at'
-    rule['value'] = 'stored'
-    rule['action'] ='error'
-    stream.send(message)
+    send_gadget_current_activity_changed_msg(stream, 'bob at localhost', '0',
+        'activity4', 'room4 at conference.localhost')
 
     # Gadget changed Alice's current-activity to none as it doesn't
     # know the activity
diff --git a/tests/twisted/olpc/util.py b/tests/twisted/olpc/util.py
index e9539ad..7b3efef 100644
--- a/tests/twisted/olpc/util.py
+++ b/tests/twisted/olpc/util.py
@@ -135,3 +135,16 @@ def answer_error_to_pubsub_request(stream, request, node):
     error.addElement((NS_STANZA, 'not-authorized'))
     error.addElement(("%s#errors" % NS_PUBSUB, 'presence-subscription-required'))
     stream.send(reply)
+
+def send_gadget_current_activity_changed_msg(stream, buddy, view_id, id, room):
+    # FIXME: should be id and not type !
+    message = elem('message', from_='gadget.localhost',
+        to='test at localhost', type='notice')(
+            elem(NS_OLPC_BUDDY, 'change', jid=buddy, id=view_id)(
+                elem(NS_OLPC_CURRENT_ACTIVITY, 'activity', type=id, room=room)()
+                ),
+            elem(NS_AMP, 'amp')(
+                elem('rule', condition='deliver-at', value='stored',
+                    action='error')))
+
+    stream.send(message)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list