[Telepathy-commits] [telepathy-gabble/master] Add a regression test for roster groups

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Aug 19 10:51:49 PDT 2008


20080423113647-53eee-88f64055934cb5c54613267847ca237a2798143a.gz
---
 tests/twisted/Makefile.am      |    1 +
 tests/twisted/roster/groups.py |   75 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 tests/twisted/roster/groups.py

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 25ed489..8e130f7 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -7,6 +7,7 @@ TWISTED_TESTS = \
 	olpc/olpc-muc-prop-change.py \
 	olpc/test-olpc-bundle.py \
 	olpc/test-olpc-set-props-preload.py \
+	roster/groups.py \
 	roster/test-google-roster.py \
 	roster/test-roster.py \
 	roster/test-roster-subscribe.py \
diff --git a/tests/twisted/roster/groups.py b/tests/twisted/roster/groups.py
new file mode 100644
index 0000000..10d9c14
--- /dev/null
+++ b/tests/twisted/roster/groups.py
@@ -0,0 +1,75 @@
+
+"""
+Test basic roster functionality.
+"""
+
+import dbus
+
+from gabbletest import exec_test
+
+
+HT_CONTACT_LIST = 3
+HT_GROUP = 4
+
+
+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 == u'org.freedesktop.Telepathy.Channel.Type.ContactList'
+    assert handle_type == HT_CONTACT_LIST
+    assert conn.InspectHandles(handle_type, [handle])[0] == name
+    chan = bus.get_object(conn._named_service, path)
+    group_iface = dbus.Interface(chan,
+        u'org.freedesktop.Telepathy.Channel.Interface.Group')
+    assert conn.InspectHandles(1, group_iface.GetMembers()) == 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 == u'org.freedesktop.Telepathy.Channel.Type.ContactList'
+    assert handle_type == HT_GROUP
+    assert conn.InspectHandles(handle_type, [handle])[0] == name
+    chan = bus.get_object(conn._named_service, path)
+    group_iface = dbus.Interface(chan,
+        u'org.freedesktop.Telepathy.Channel.Interface.Group')
+    assert conn.InspectHandles(1, group_iface.GetMembers()) == contacts
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+    event = q.expect('stream-iq', query_ns='jabber:iq:roster')
+    event.stanza['type'] = 'result'
+
+    item = event.query.addElement('item')
+    item['jid'] = 'amy at foo.com'
+    item['subscription'] = 'both'
+    group = item.addElement('group', content='women')
+
+    item = event.query.addElement('item')
+    item['jid'] = 'bob at foo.com'
+    item['subscription'] = 'from'
+    group = item.addElement('group', content='men')
+
+    item = event.query.addElement('item')
+    item['jid'] = 'che at foo.com'
+    item['subscription'] = 'to'
+    group = item.addElement('group', content='men')
+
+    stream.send(event.stanza)
+
+    _expect_contact_list_channel(q, bus, conn, 'publish',
+        ['amy at foo.com', 'bob at foo.com'])
+    _expect_contact_list_channel(q, bus, conn, 'subscribe',
+        ['amy at foo.com', 'che at foo.com'])
+    _expect_contact_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'])
+
+    conn.Disconnect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+if __name__ == '__main__':
+    exec_test(test)
+
-- 
1.5.6.3




More information about the Telepathy-commits mailing list