[telepathy-gabble/master] Share best version of _expect_contact_list_channel
Will Thompson
will.thompson at collabora.co.uk
Thu May 21 04:10:35 PDT 2009
---
tests/twisted/gabbletest.py | 69 ++++++++++++++++++++-
tests/twisted/roster/groups-12791.py | 20 +-----
tests/twisted/roster/groups.py | 43 ++-----------
tests/twisted/roster/test-roster-item-deletion.py | 35 +++--------
tests/twisted/roster/test-roster.py | 68 ++------------------
5 files changed, 93 insertions(+), 142 deletions(-)
diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index 8f2058c..9d4bb04 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -10,8 +10,11 @@ import sys
import random
import ns
+import constants as cs
import servicetest
-from servicetest import assertEquals, assertLength
+from servicetest import (
+ assertEquals, assertLength, assertContains, wrap_channel, EventPattern,
+ )
import twisted
from twisted.words.xish import domish, xpath
from twisted.words.protocols.jabber.client import IQ
@@ -510,3 +513,67 @@ def make_presence(_from, to='test at localhost', type=None, status=None, caps=None)
cel[key] = value
return presence
+
+def expect_list_channel(q, bus, conn, name, contacts):
+ return expect_contact_list_channel(q, bus, conn, cs.HT_CONTACT_LIST, name,
+ contacts)
+
+def expect_group_channel(q, bus, conn, name, contacts):
+ return expect_contact_list_channel(q, bus, conn, cs.HT_GROUP, name,
+ contacts)
+
+def expect_contact_list_channel(q, bus, conn, ht, name, contacts):
+ """
+ Expects NewChannel and NewChannels signals for the
+ contact list with handle type 'ht' and ID 'name', and checks that its
+ members are exactly 'contacts'. Returns a proxy for the channel.
+ """
+
+ old_signal, new_signal = q.expect_many(
+ EventPattern('dbus-signal', signal='NewChannel'),
+ EventPattern('dbus-signal', signal='NewChannels'),
+ )
+
+ path, type, handle_type, handle, suppress_handler = old_signal.args
+
+ assertEquals(cs.CHANNEL_TYPE_CONTACT_LIST, type)
+ assertEquals(name, conn.InspectHandles(handle_type, [handle])[0])
+
+ chan = wrap_channel(bus.get_object(conn.bus_name, path),
+ cs.CHANNEL_TYPE_CONTACT_LIST)
+ members = chan.Group.GetMembers()
+
+ assertEquals(contacts, conn.InspectHandles(cs.HT_CONTACT, members))
+
+ # NB. comma: we're unpacking args. Thython!
+ info, = new_signal.args
+ assertLength(1, info) # one channel
+ path_, emitted_props = info[0]
+
+ assertEquals(path_, path)
+
+ assertEquals(cs.CHANNEL_TYPE_CONTACT_LIST, emitted_props[cs.CHANNEL_TYPE])
+ assertEquals(ht, emitted_props[cs.TARGET_HANDLE_TYPE])
+ assertEquals(handle, emitted_props[cs.TARGET_HANDLE])
+
+ channel_props = chan.Properties.GetAll(cs.CHANNEL)
+ assertEquals(handle, channel_props.get('TargetHandle'))
+ assertEquals(ht, channel_props.get('TargetHandleType'))
+ assertEquals(cs.CHANNEL_TYPE_CONTACT_LIST, channel_props.get('ChannelType'))
+ assertContains(cs.CHANNEL_IFACE_GROUP, channel_props.get('Interfaces'))
+ assertEquals(name, channel_props['TargetID'])
+ assertEquals(False, channel_props['Requested'])
+ assertEquals('', channel_props['InitiatorID'])
+ assertEquals(0, channel_props['InitiatorHandle'])
+
+ group_props = chan.Properties.GetAll(cs.CHANNEL_IFACE_GROUP)
+ assertContains('HandleOwners', group_props)
+ assertContains('Members', group_props)
+ assertEquals(members, group_props['Members'])
+ assertContains('LocalPendingMembers', group_props)
+ assertEquals([], group_props['LocalPendingMembers'])
+ assertContains('RemotePendingMembers', group_props)
+ assertEquals([], group_props['RemotePendingMembers'])
+ assertContains('GroupFlags', group_props)
+
+ return chan
diff --git a/tests/twisted/roster/groups-12791.py b/tests/twisted/roster/groups-12791.py
index 8736870..6bd6cec 100644
--- a/tests/twisted/roster/groups-12791.py
+++ b/tests/twisted/roster/groups-12791.py
@@ -4,21 +4,9 @@ Test broken groups on the roster (regression test for fd.o #12791)
import dbus
-from gabbletest import exec_test
+from gabbletest import exec_test, expect_list_channel
import constants as cs
-def _expect_contact_list_channel(q, bus, conn, name, contacts):
- event = q.expect('dbus-signal', signal='NewChannel')
- path, type, handle_type, handle, suppress_handler = event.args
- assert type == cs.CHANNEL_TYPE_CONTACT_LIST, type
- assert handle_type == cs.HT_CONTACT_LIST, handle_type
- inspected = conn.InspectHandles(handle_type, [handle])[0]
- assert inspected == name, (inspected, name)
- chan = bus.get_object(conn.bus_name, path)
- group_iface = dbus.Interface(chan, cs.CHANNEL_IFACE_GROUP)
- inspected = conn.InspectHandles(cs.HT_CONTACT, group_iface.GetMembers())
- assert inspected == contacts, (inspected, contacts)
-
def _expect_group_channel(q, bus, conn, name, contacts):
event = q.expect('dbus-signal', signal='NewChannel')
path, type, handle_type, handle, suppress_handler = event.args
@@ -76,11 +64,11 @@ def test(q, bus, conn, stream):
# FIXME: this is somewhat fragile - it's asserting the exact order that
# things currently happen in roster.c. In reality the order is not
# significant
- _expect_contact_list_channel(q, bus, conn, 'publish',
+ expect_list_channel(q, bus, conn, 'publish',
['amy at foo.com', 'bob at foo.com'])
- _expect_contact_list_channel(q, bus, conn, 'subscribe',
+ expect_list_channel(q, bus, conn, 'subscribe',
['amy at foo.com', 'che at foo.com'])
- _expect_contact_list_channel(q, bus, conn, 'known',
+ expect_list_channel(q, bus, conn, 'known',
['amy at foo.com', 'bob at foo.com', 'che at foo.com'])
_expect_group_channel(q, bus, conn, 'women', ['amy at foo.com'])
_expect_group_channel(q, bus, conn, 'affected-by-fdo-12791', [])
diff --git a/tests/twisted/roster/groups.py b/tests/twisted/roster/groups.py
index 54a70a1..bde2635 100644
--- a/tests/twisted/roster/groups.py
+++ b/tests/twisted/roster/groups.py
@@ -4,40 +4,9 @@ Test basic roster functionality.
import dbus
-from gabbletest import exec_test
+from gabbletest import exec_test, expect_list_channel, expect_group_channel
import constants as cs
-def _expect_contact_list_channel(q, bus, conn, name, contacts):
- event = q.expect('dbus-signal', signal='NewChannel')
- path, type, handle_type, handle, suppress_handler = event.args
- assert type == cs.CHANNEL_TYPE_CONTACT_LIST, type
- assert handle_type == cs.HT_CONTACT_LIST, handle_type
- inspected = conn.InspectHandles(handle_type, [handle])[0]
- assert inspected == name, (inspected, name)
- chan = bus.get_object(conn.bus_name, path)
- group_iface = dbus.Interface(chan, cs.CHANNEL_IFACE_GROUP)
- inspected = conn.InspectHandles(cs.HT_CONTACT, group_iface.GetMembers())
- assert inspected == contacts, (inspected, contacts)
-
-def _expect_group_channel(q, bus, conn, name, contacts):
- event = q.expect('dbus-signal', signal='NewChannel')
- path, type, handle_type, handle, suppress_handler = event.args
- assert type == cs.CHANNEL_TYPE_CONTACT_LIST, type
- assert handle_type == cs.HT_GROUP, handle_type
- inspected = conn.InspectHandles(handle_type, [handle])[0]
- assert inspected == name, (inspected, name)
- chan = bus.get_object(conn.bus_name, path)
- group_iface = dbus.Interface(chan, cs.CHANNEL_IFACE_GROUP)
- inspected = conn.InspectHandles(cs.HT_CONTACT, group_iface.GetMembers())
- assert inspected == contacts, (inspected, contacts)
-
- channel_props = chan.GetAll(
- cs.CHANNEL, dbus_interface=dbus.PROPERTIES_IFACE)
- assert channel_props['TargetID'] == name, channel_props
- assert channel_props['Requested'] == False
- assert channel_props['InitiatorID'] == ''
- assert channel_props['InitiatorHandle'] == 0
-
def test(q, bus, conn, stream):
conn.Connect()
# q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
@@ -65,14 +34,14 @@ def test(q, bus, conn, stream):
# FIXME: this is somewhat fragile - it's asserting the exact order that
# things currently happen in roster.c. In reality the order is not
# significant
- _expect_contact_list_channel(q, bus, conn, 'publish',
+ expect_list_channel(q, bus, conn, 'publish',
['amy at foo.com', 'bob at foo.com'])
- _expect_contact_list_channel(q, bus, conn, 'subscribe',
+ expect_list_channel(q, bus, conn, 'subscribe',
['amy at foo.com', 'che at foo.com'])
- _expect_contact_list_channel(q, bus, conn, 'known',
+ expect_list_channel(q, bus, conn, 'known',
['amy at foo.com', 'bob at foo.com', 'che at foo.com'])
- _expect_group_channel(q, bus, conn, 'women', ['amy at foo.com'])
- _expect_group_channel(q, bus, conn, 'men', ['bob at foo.com', 'che at foo.com'])
+ expect_group_channel(q, bus, conn, 'women', ['amy at foo.com'])
+ expect_group_channel(q, bus, conn, 'men', ['bob at foo.com', 'che at foo.com'])
conn.Disconnect()
q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
diff --git a/tests/twisted/roster/test-roster-item-deletion.py b/tests/twisted/roster/test-roster-item-deletion.py
index 238c86f..d7ff97b 100644
--- a/tests/twisted/roster/test-roster-item-deletion.py
+++ b/tests/twisted/roster/test-roster-item-deletion.py
@@ -6,26 +6,7 @@ import dbus
from twisted.words.protocols.jabber.client import IQ
-from gabbletest import exec_test, acknowledge_iq
-from servicetest import EventPattern
-import constants as cs
-
-def _expect_contact_list_channel(q, bus, conn, name, contacts):
- old_signal, new_signal = q.expect_many(
- EventPattern('dbus-signal', signal='NewChannel'),
- EventPattern('dbus-signal', signal='NewChannels'),
- )
-
- path, type, handle_type, handle, suppress_handler = old_signal.args
-
- assert type == cs.CHANNEL_TYPE_CONTACT_LIST
- assert conn.InspectHandles(handle_type, [handle])[0] == name
- chan = bus.get_object(conn.bus_name, path)
- group_iface = dbus.Interface(chan, cs.CHANNEL_IFACE_GROUP)
- members = group_iface.GetMembers()
- assert conn.InspectHandles(1, members) == contacts
-
- return chan, group_iface
+from gabbletest import exec_test, acknowledge_iq, expect_list_channel
def test(q, bus, conn, stream):
conn.Connect()
@@ -49,14 +30,14 @@ def test(q, bus, conn, stream):
stream.send(event.stanza)
- k0, i0 = _expect_contact_list_channel(q, bus, conn, 'publish',
- [])
- k1, i1 = _expect_contact_list_channel(q, bus, conn, 'subscribe',
- [])
- k, i = _expect_contact_list_channel(q, bus, conn, 'known',
- ['quux at foo.com'])
+ # FIXME: this is somewhat fragile - it's asserting the exact order that
+ # things currently happen in roster.c. In reality the order is not
+ # significant
+ publish = expect_list_channel(q, bus, conn, 'publish', [])
+ subscribe = expect_list_channel(q, bus, conn, 'subscribe', [])
+ known = expect_list_channel(q, bus, conn, 'known', ['quux at foo.com'])
- i.RemoveMembers([dbus.UInt32(2)], '')
+ known.Group.RemoveMembers([dbus.UInt32(2)], '')
send_roster_iq(stream, 'quux at foo.com', 'remove')
acknowledge_iq(stream, q.expect('stream-iq').stanza)
diff --git a/tests/twisted/roster/test-roster.py b/tests/twisted/roster/test-roster.py
index 937574b..6a5df44 100644
--- a/tests/twisted/roster/test-roster.py
+++ b/tests/twisted/roster/test-roster.py
@@ -4,64 +4,7 @@ Test basic roster functionality.
import dbus
-from gabbletest import exec_test
-from servicetest import EventPattern
-import constants as cs
-
-def _expect_contact_list_channel(q, bus, conn, name, contacts):
- old_signal, new_signal = q.expect_many(
- EventPattern('dbus-signal', signal='NewChannel'),
- EventPattern('dbus-signal', signal='NewChannels'),
- )
-
- path, type, handle_type, handle, suppress_handler = old_signal.args
-
- assert type == cs.CHANNEL_TYPE_CONTACT_LIST
- assert conn.InspectHandles(handle_type, [handle])[0] == name
- chan = bus.get_object(conn.bus_name, path)
- group_iface = dbus.Interface(chan, cs.CHANNEL_IFACE_GROUP)
- members = group_iface.GetMembers()
- assert conn.InspectHandles(1, members) == contacts
-
- assert len(new_signal.args) == 1
- assert len(new_signal.args[0]) == 1 # one channel
- assert len(new_signal.args[0][0]) == 2 # two struct members
- assert new_signal.args[0][0][0] == path
-
- emitted_props = new_signal.args[0][0][1]
- assert emitted_props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_CONTACT_LIST
- assert emitted_props[cs.TARGET_HANDLE_TYPE] == cs.HT_CONTACT_LIST
- assert emitted_props[cs.TARGET_HANDLE] == handle
-
- # Exercise basic Channel Properties from spec 0.17.7
- channel_props = chan.GetAll(
- cs.CHANNEL, dbus_interface=dbus.PROPERTIES_IFACE)
- assert channel_props.get('TargetHandle') == handle,\
- (channel_props.get('TargetHandle'), handle)
- assert channel_props.get('TargetHandleType') == 3,\
- channel_props.get('TargetHandleType')
- assert channel_props.get('ChannelType') == \
- cs.CHANNEL_TYPE_CONTACT_LIST,\
- channel_props.get('ChannelType')
- assert cs.CHANNEL_IFACE_GROUP in \
- channel_props.get('Interfaces', ()), \
- channel_props.get('Interfaces')
- assert channel_props['TargetID'] == name, channel_props
- assert channel_props['Requested'] == False
- assert channel_props['InitiatorID'] == ''
- assert channel_props['InitiatorHandle'] == 0
-
- # Exercise Group Properties from spec 0.17.6 (in a basic way)
- group_props = chan.GetAll(
- cs.CHANNEL_IFACE_GROUP, dbus_interface=dbus.PROPERTIES_IFACE)
- assert 'HandleOwners' in group_props, group_props
- assert 'Members' in group_props, group_props
- assert group_props['Members'] == members, group_props['Members']
- assert 'LocalPendingMembers' in group_props, group_props
- assert group_props['LocalPendingMembers'] == []
- assert 'RemotePendingMembers' in group_props, group_props
- assert group_props['RemotePendingMembers'] == []
- assert 'GroupFlags' in group_props, group_props
+from gabbletest import exec_test, expect_list_channel
def test(q, bus, conn, stream):
conn.Connect()
@@ -84,11 +27,14 @@ def test(q, bus, conn, stream):
stream.send(event.stanza)
- _expect_contact_list_channel(q, bus, conn, 'publish',
+ # FIXME: this is somewhat fragile - it's asserting the exact order that
+ # things currently happen in roster.c. In reality the order is not
+ # significant
+ expect_list_channel(q, bus, conn, 'publish',
['amy at foo.com', 'bob at foo.com'])
- _expect_contact_list_channel(q, bus, conn, 'subscribe',
+ expect_list_channel(q, bus, conn, 'subscribe',
['amy at foo.com', 'che at foo.com'])
- _expect_contact_list_channel(q, bus, conn, 'known',
+ expect_list_channel(q, bus, conn, 'known',
['amy at foo.com', 'bob at foo.com', 'che at foo.com'])
conn.Disconnect()
--
1.5.6.5
More information about the telepathy-commits
mailing list