[Telepathy-commits] [telepathy-gabble/master] util.py: use ns.py
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Mon Oct 20 03:45:56 PDT 2008
---
tests/twisted/olpc/util.py | 60 +++++++++++++++++--------------------------
1 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/tests/twisted/olpc/util.py b/tests/twisted/olpc/util.py
index 7a6d221..55e3dff 100644
--- a/tests/twisted/olpc/util.py
+++ b/tests/twisted/olpc/util.py
@@ -4,19 +4,7 @@ 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
-
-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_DISCO_INFO = "http://jabber.org/protocol/disco#info"
-NS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items"
-NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
-NS_AMP = "http://jabber.org/protocol/amp"
-NS_STANZA = "urn:ietf:params:xml:ns:xmpp-stanzas"
+import ns
# Copied from Gadget
valid_types = ['str', 'int', 'uint', 'bool', 'bytes']
@@ -68,13 +56,13 @@ def announce_gadget(q, stream, disco_stanza):
stream.send(reply)
# wait for Gadget disco#info query
- event = q.expect('stream-iq', to='gadget.localhost', query_ns=NS_DISCO_INFO)
+ event = q.expect('stream-iq', to='gadget.localhost', query_ns=ns.DISCO_INFO)
reply = elem_iq(stream, 'result', id=event.stanza['id'])(
- elem(NS_DISCO_INFO, 'query')(
+ elem(ns.DISCO_INFO, 'query')(
elem('identity', category='collaboration', type='gadget', name='OLPC Gadget')(),
- elem('feature', var=NS_OLPC_BUDDY)(),
- elem('feature', var=NS_OLPC_ACTIVITY)()))
+ elem('feature', var=ns.OLPC_BUDDY)(),
+ elem('feature', var=ns.OLPC_ACTIVITY)()))
stream.send(reply)
@@ -83,16 +71,16 @@ def _make_pubsub_event_msg(from_, node):
item = domish.Element((None, 'item'))
message = elem('message', from_=from_, to='test at localhost')(
- elem("%s#event" % NS_PUBSUB, 'event')(
+ elem("%s#event" % ns.PUBSUB, 'event')(
elem('items', node=node)(item)))
return message, item
def send_buddy_changed_properties_msg(stream, from_, props):
message, item = _make_pubsub_event_msg(from_,
- NS_OLPC_BUDDY_PROPS)
+ ns.OLPC_BUDDY_PROPS)
- properties = item.addElement((NS_OLPC_BUDDY_PROPS, 'properties'))
+ properties = item.addElement((ns.OLPC_BUDDY_PROPS, 'properties'))
for child in properties_to_xml(props):
properties.addChild(child)
@@ -101,9 +89,9 @@ def send_buddy_changed_properties_msg(stream, from_, props):
def send_buddy_changed_current_act_msg(stream, from_, id, room):
message, item = _make_pubsub_event_msg(from_,
- NS_OLPC_CURRENT_ACTIVITY)
+ ns.OLPC_CURRENT_ACTIVITY)
- activity = item.addElement((NS_OLPC_CURRENT_ACTIVITY, 'activity'))
+ activity = item.addElement((ns.OLPC_CURRENT_ACTIVITY, 'activity'))
activity['room'] = room
activity['type'] = id
@@ -113,17 +101,17 @@ def answer_to_current_act_pubsub_request(stream, request, id, room):
# check request structure
assert request['type'] == 'get'
items = xpath.queryForNodes(
- '/iq/pubsub[@xmlns="%s"]/items' % NS_PUBSUB, request)[0]
- assert items['node'] == NS_OLPC_CURRENT_ACTIVITY
+ '/iq/pubsub[@xmlns="%s"]/items' % ns.PUBSUB, request)[0]
+ assert items['node'] == ns.OLPC_CURRENT_ACTIVITY
reply = make_result_iq(stream, request)
reply['from'] = request['to']
pubsub = reply.firstChildElement()
items = pubsub.addElement((None, 'items'))
- items['node'] = NS_OLPC_CURRENT_ACTIVITY
+ items['node'] = ns.OLPC_CURRENT_ACTIVITY
item = items.addElement((None, 'item'))
item['id'] = 'itemID'
- activity = item.addElement((NS_OLPC_CURRENT_ACTIVITY, 'activity'))
+ activity = item.addElement((ns.OLPC_CURRENT_ACTIVITY, 'activity'))
activity['room'] = room
activity['type'] = id
reply.send()
@@ -136,21 +124,21 @@ def answer_error_to_pubsub_request(stream, request):
reply = IQ(stream, "error")
reply['id'] = request['id']
reply['from'] = request['to']
- pubsub = reply.addElement((NS_PUBSUB, 'pubsub'))
+ pubsub = reply.addElement((ns.PUBSUB, 'pubsub'))
items = pubsub.addElement((None, 'items'))
items['node'] = node
error = reply.addElement((None, 'error'))
error['type'] = 'auth'
- error.addElement((NS_STANZA, 'not-authorized'))
- error.addElement(("%s#errors" % NS_PUBSUB, 'presence-subscription-required'))
+ 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):
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', id=id, room=room)()),
- elem(NS_AMP, 'amp')(
+ elem(ns.OLPC_BUDDY, 'change', jid=buddy, id=view_id)(
+ elem(ns.OLPC_CURRENT_ACTIVITY, 'activity', id=id, room=room)()),
+ elem(ns.AMP, 'amp')(
elem('rule', condition='deliver-at', value='stored',
action='error')))
@@ -166,7 +154,7 @@ def send_reply_to_activity_view_request(stream, stanza, activities):
activity['room'] = room
activity['id'] = id
if props:
- properties = activity.addElement((NS_OLPC_ACTIVITY_PROPS,
+ properties = activity.addElement((ns.OLPC_ACTIVITY_PROPS,
"properties"))
for child in properties_to_xml(props):
properties.addChild(child)
@@ -175,7 +163,7 @@ def send_reply_to_activity_view_request(stream, stanza, activities):
buddy = activity.addElement((None, 'buddy'))
buddy['jid'] = jid
if props:
- properties = buddy.addElement((NS_OLPC_BUDDY_PROPS,
+ properties = buddy.addElement((ns.OLPC_BUDDY_PROPS,
"properties"))
for child in properties_to_xml(props):
properties.addChild(child)
@@ -193,7 +181,7 @@ def request_random_activity_view(q, stream, conn, max, id, activities):
iq_event, return_event = q.expect_many(
EventPattern('stream-iq', to='gadget.localhost',
- query_ns=NS_OLPC_ACTIVITY),
+ query_ns=ns.OLPC_ACTIVITY),
EventPattern('dbus-return', method='CreateChannel'))
view = iq_event.stanza.firstChildElement()
@@ -235,7 +223,7 @@ def create_gadget_message(to):
message['from'] = 'gadget.localhost'
message['to'] = to
message['type'] = 'notice'
- amp = message.addElement((NS_AMP, 'amp'))
+ amp = message.addElement((ns.AMP, 'amp'))
rule = amp.addElement((None, 'rule'))
rule['condition'] = 'deliver-at'
rule['value'] = 'stored'
--
1.5.6.5
More information about the Telepathy-commits
mailing list