[Telepathy-commits] [telepathy-gabble/master] olpc/olpc-buddy-search.py: use create_gadget_message

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 26 07:48:26 PDT 2008


---
 tests/twisted/olpc/olpc-activity-search.py |   15 +----------
 tests/twisted/olpc/olpc-buddy-search.py    |   38 +++++++--------------------
 tests/twisted/olpc/util.py                 |   13 +++++++++
 3 files changed, 24 insertions(+), 42 deletions(-)

diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 634977d..a5aca4f 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -11,7 +11,7 @@ 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, send_reply_to_activity_view_request,
-    parse_properties, properties_to_xml)
+    parse_properties, properties_to_xml, create_gadget_message)
 
 NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
 NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
@@ -44,19 +44,6 @@ def close_view(q, view_iface, id):
     assert len(close) == 1
     assert close[0]['id'] == id
 
-def create_gadget_message(to):
-    message = domish.Element((None, 'message'))
-    message['from'] = 'gadget.localhost'
-    message['to'] = to
-    message['type'] = 'notice'
-    amp = message.addElement((NS_AMP, 'amp'))
-    rule = amp.addElement((None, 'rule'))
-    rule['condition'] = 'deliver-at'
-    rule['value'] = 'stored'
-    rule['action'] ='error'
-
-    return message
-
 def test(q, bus, conn, stream):
     conn.Connect()
 
diff --git a/tests/twisted/olpc/olpc-buddy-search.py b/tests/twisted/olpc/olpc-buddy-search.py
index 39a4cac..91ece56 100644
--- a/tests/twisted/olpc/olpc-buddy-search.py
+++ b/tests/twisted/olpc/olpc-buddy-search.py
@@ -10,7 +10,8 @@ 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
 
-from util import announce_gadget, properties_to_xml, parse_properties
+from util import (announce_gadget, properties_to_xml, parse_properties,
+    create_gadget_message)
 
 NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
 NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
@@ -138,10 +139,7 @@ def test(q, bus, conn, stream):
     assert props == {'color': '#005FE4,#00A0FF'}
 
     # Bob changed his properties
-    message = domish.Element(('jabber:client', 'message'))
-    message['from'] = 'gadget.localhost'
-    message['to'] = 'test at localhost'
-    message['type'] = 'notice'
+    message = create_gadget_message("test at localhost")
 
     change = message.addElement((NS_OLPC_BUDDY, 'change'))
     change['jid'] = 'bob at localhost'
@@ -149,11 +147,7 @@ def test(q, bus, conn, stream):
     properties = change.addElement((NS_OLPC_BUDDY_PROPS, 'properties'))
     for node in properties_to_xml({'color': ('str', '#FFFFFF,#AAAAAA')}):
         properties.addChild(node)
-    amp = message.addElement((NS_AMP, 'amp'))
-    rule = amp.addElement((None, 'rule'))
-    rule['condition'] = 'deliver-at'
-    rule['value'] = 'stored'
-    rule['action'] ='error'
+
     stream.send(message)
 
     event = q.expect('dbus-signal', signal='PropertiesChanged',
@@ -209,10 +203,8 @@ def test(q, bus, conn, stream):
     assert props == {'color': '#AABBCC,#001122'}
 
     # add a buddy to view 0
-    message = domish.Element((None, 'message'))
-    message['from'] = 'gadget.localhost'
-    message['to'] = 'alice at localhost'
-    message['type'] = 'notice'
+    message = create_gadget_message("test at localhost")
+
     added = message.addElement((NS_OLPC_BUDDY, 'added'))
     added['id'] = '0'
     buddy = added.addElement((None, 'buddy'))
@@ -220,11 +212,7 @@ def test(q, bus, conn, stream):
     properties = buddy.addElement((NS_OLPC_BUDDY_PROPS, "properties"))
     for node in properties_to_xml({'color': ('str', '#000000,#AAAAAA')}):
         properties.addChild(node)
-    amp = message.addElement((NS_AMP, 'amp'))
-    rule = amp.addElement((None, 'rule'))
-    rule['condition'] = 'deliver-at'
-    rule['value'] = 'stored'
-    rule['action'] ='error'
+
     stream.send(message)
 
     event = q.expect('dbus-signal', signal='BuddiesChanged')
@@ -240,19 +228,13 @@ def test(q, bus, conn, stream):
             'oscar at localhost']
 
     # remove a buddy from view 0
-    message = domish.Element((None, 'message'))
-    message['from'] = 'gadget.localhost'
-    message['to'] = 'alice at localhost'
-    message['type'] = 'notice'
+    message = create_gadget_message("test at localhost")
+
     added = message.addElement((NS_OLPC_BUDDY, 'removed'))
     added['id'] = '0'
     buddy = added.addElement((None, 'buddy'))
     buddy['jid'] = 'bob at 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)
 
     event = q.expect('dbus-signal', signal='BuddiesChanged')
diff --git a/tests/twisted/olpc/util.py b/tests/twisted/olpc/util.py
index 2c1ba37..bf0996b 100644
--- a/tests/twisted/olpc/util.py
+++ b/tests/twisted/olpc/util.py
@@ -211,3 +211,16 @@ def xpath_query(query, elem):
         return []
     else:
         return nodes
+
+def create_gadget_message(to):
+    message = domish.Element((None, 'message'))
+    message['from'] = 'gadget.localhost'
+    message['to'] = to
+    message['type'] = 'notice'
+    amp = message.addElement((NS_AMP, 'amp'))
+    rule = amp.addElement((None, 'rule'))
+    rule['condition'] = 'deliver-at'
+    rule['value'] = 'stored'
+    rule['action'] ='error'
+
+    return message
-- 
1.5.6.5




More information about the Telepathy-commits mailing list