[Telepathy-commits] [telepathy-gabble/master] tests/twisted/tubes: extract "get MUC Tubes" boilerplate
Will Thompson
will.thompson at collabora.co.uk
Thu Dec 25 03:04:16 PST 2008
---
tests/twisted/tubes/muctubeutil.py | 68 +++++++++++++++++++++++
tests/twisted/tubes/test-muc-offer-dbus-tube.py | 56 +-----------------
2 files changed, 72 insertions(+), 52 deletions(-)
create mode 100644 tests/twisted/tubes/muctubeutil.py
diff --git a/tests/twisted/tubes/muctubeutil.py b/tests/twisted/tubes/muctubeutil.py
new file mode 100644
index 0000000..8e2a7e6
--- /dev/null
+++ b/tests/twisted/tubes/muctubeutil.py
@@ -0,0 +1,68 @@
+import dbus
+
+from servicetest import call_async, EventPattern, tp_name_prefix
+from gabbletest import make_result_iq, acknowledge_iq
+
+from twisted.words.xish import domish, xpath
+
+def get_muc_tubes_channel(q, bus, conn, stream, muc_jid):
+ """
+ Returns a singleton list containing the MUC's handle, a proxy for the Tubes
+ channel, and a proxy for the Tubes iface on that channel.
+ """
+ muc_server = muc_jid.split('@')[1]
+ test_jid = muc_jid + "/test"
+ bob_jid = muc_jid + "/bob"
+
+ call_async(q, conn, 'RequestHandles', 2, [muc_jid])
+
+ event = q.expect('stream-iq', to=muc_server,
+ query_ns='http://jabber.org/protocol/disco#info')
+ result = make_result_iq(stream, event.stanza)
+ feature = result.firstChildElement().addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/muc'
+ stream.send(result)
+
+ event = q.expect('dbus-return', method='RequestHandles')
+ handles = event.value[0]
+
+ # request tubes channel
+ call_async(q, conn, 'RequestChannel',
+ tp_name_prefix + '.Channel.Type.Tubes', 2, handles[0], True)
+
+ _, stream_event = q.expect_many(
+ EventPattern('dbus-signal', signal='MembersChanged',
+ args=[u'', [], [], [], [2], 0, 0]),
+ EventPattern('stream-presence', to=test_jid))
+
+ # Send presence for other member of room.
+ presence = domish.Element((None, 'presence'))
+ presence['from'] = bob_jid
+ x = presence.addElement(('http://jabber.org/protocol/muc#user', 'x'))
+ item = x.addElement('item')
+ item['affiliation'] = 'owner'
+ item['role'] = 'moderator'
+ stream.send(presence)
+
+ # Send presence for own membership of room.
+ presence = domish.Element((None, 'presence'))
+ presence['from'] = test_jid
+ x = presence.addElement(('http://jabber.org/protocol/muc#user', 'x'))
+ item = x.addElement('item')
+ item['affiliation'] = 'none'
+ item['role'] = 'participant'
+ stream.send(presence)
+
+ q.expect('dbus-signal', signal='MembersChanged',
+ args=[u'', [2, 3], [], [], [], 0, 0])
+
+ assert conn.InspectHandles(1, [2]) == [test_jid]
+ assert conn.InspectHandles(1, [3]) == [bob_jid]
+
+ event = q.expect('dbus-return', method='RequestChannel')
+
+ tubes_chan = bus.get_object(conn.bus_name, event.value[0])
+ tubes_iface = dbus.Interface(tubes_chan,
+ tp_name_prefix + '.Channel.Type.Tubes')
+
+ return (handles, tubes_chan, tubes_iface)
diff --git a/tests/twisted/tubes/test-muc-offer-dbus-tube.py b/tests/twisted/tubes/test-muc-offer-dbus-tube.py
index 9746831..b4b0fb1 100644
--- a/tests/twisted/tubes/test-muc-offer-dbus-tube.py
+++ b/tests/twisted/tubes/test-muc-offer-dbus-tube.py
@@ -11,6 +11,8 @@ from gabbletest import exec_test, make_result_iq, acknowledge_iq
from twisted.words.xish import domish, xpath
+from muctubeutil import get_muc_tubes_channel
+
sample_parameters = dbus.Dictionary({
's': 'hello',
'ay': dbus.ByteArray('hello'),
@@ -35,58 +37,8 @@ def test(q, bus, conn, stream):
acknowledge_iq(stream, iq_event.stanza)
- call_async(q, conn, 'RequestHandles', 2,
- ['chat at conf.localhost'])
-
- event = q.expect('stream-iq', to='conf.localhost',
- query_ns='http://jabber.org/protocol/disco#info')
- result = make_result_iq(stream, event.stanza)
- feature = result.firstChildElement().addElement('feature')
- feature['var'] = 'http://jabber.org/protocol/muc'
- stream.send(result)
-
- event = q.expect('dbus-return', method='RequestHandles')
- handles = event.value[0]
-
- # request tubes channel
- call_async(q, conn, 'RequestChannel',
- tp_name_prefix + '.Channel.Type.Tubes', 2, handles[0], True)
-
- _, stream_event = q.expect_many(
- EventPattern('dbus-signal', signal='MembersChanged',
- args=[u'', [], [], [], [2], 0, 0]),
- EventPattern('stream-presence', to='chat at conf.localhost/test'))
-
- # Send presence for other member of room.
- presence = domish.Element((None, 'presence'))
- presence['from'] = 'chat at conf.localhost/bob'
- x = presence.addElement(('http://jabber.org/protocol/muc#user', 'x'))
- item = x.addElement('item')
- item['affiliation'] = 'owner'
- item['role'] = 'moderator'
- stream.send(presence)
-
- # Send presence for own membership of room.
- presence = domish.Element((None, 'presence'))
- presence['from'] = 'chat at conf.localhost/test'
- x = presence.addElement(('http://jabber.org/protocol/muc#user', 'x'))
- item = x.addElement('item')
- item['affiliation'] = 'none'
- item['role'] = 'participant'
- stream.send(presence)
-
- q.expect('dbus-signal', signal='MembersChanged',
- args=[u'', [2, 3], [], [], [], 0, 0])
-
- assert conn.InspectHandles(1, [2]) == ['chat at conf.localhost/test']
- assert conn.InspectHandles(1, [3]) == ['chat at conf.localhost/bob']
- bob_handle = 3
-
- event = q.expect('dbus-return', method='RequestChannel')
-
- tubes_chan = bus.get_object(conn.bus_name, event.value[0])
- tubes_iface = dbus.Interface(tubes_chan,
- tp_name_prefix + '.Channel.Type.Tubes')
+ handles, tubes_chan, tubes_iface = get_muc_tubes_channel(q, bus, conn,
+ stream, 'chat at conf.localhost')
# Exercise basic Channel Properties from spec 0.17.7
channel_props = tubes_chan.GetAll(
--
1.5.6.5
More information about the Telepathy-commits
mailing list