telepathy-gabble: rostertest: add helper for tests using the new ContactList API

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Tue Oct 8 12:53:34 PDT 2013


Module: telepathy-gabble
Branch: master
Commit: dc7b9991fc1753368c45ac85e14ed3f0f91e5762
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=dc7b9991fc1753368c45ac85e14ed3f0f91e5762

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Tue Oct  8 13:03:32 2013 -0400

rostertest: add helper for tests using the new ContactList API

---

 tests/twisted/rostertest.py |   57 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/tests/twisted/rostertest.py b/tests/twisted/rostertest.py
index d861962..86e91b1 100644
--- a/tests/twisted/rostertest.py
+++ b/tests/twisted/rostertest.py
@@ -2,7 +2,7 @@ from twisted.words.protocols.jabber.client import IQ
 
 from gabbletest import (wrap_channel,)
 from servicetest import (assertEquals, assertLength, EventPattern,
-        assertContains)
+        assertContains, assertSameSets)
 
 import constants as cs
 import ns
@@ -168,3 +168,58 @@ def check_contact_list_signals(q, bus, conn, signals,
     assertContains('GroupFlags', group_props)
 
     return chan
+
+# check that @contact on @conn is in groups @groups with @subscribe and
+# @publish as subscription states
+def check_contact_roster(conn, contact, groups=None, subscribe=None, publish=None):
+    h = conn.get_contact_handle_sync(contact)
+    attrs = conn.Contacts.GetContactAttributes([h],
+            [cs.CONN_IFACE_CONTACT_LIST, cs.CONN_IFACE_CONTACT_GROUPS], True)[h]
+
+    if groups is not None:
+        assertSameSets(groups, attrs[cs.ATTR_GROUPS])
+    if subscribe is not None:
+        assertEquals(subscribe, attrs[cs.ATTR_SUBSCRIBE])
+    if publish is not None:
+        assertEquals(publish, attrs[cs.ATTR_PUBLISH])
+
+# function to pass as 'ContactsChangedWithID' dbus-signal even predicate
+# checking if the (contact-id, subscribe-state, publish-state, message) tuples
+# from @contacts are the arguments of the signal.
+def contacts_changed_predicate(e, conn, contacts):
+    changes, ids, removals = e.args
+
+    if len(changes) != len(contacts):
+        return False
+
+    for c in contacts:
+        i, subscribe, publish, msg = c
+
+        h = conn.get_contact_handle_sync(i)
+
+        if changes[h] != (subscribe, publish, msg):
+            return False
+
+    return True
+
+# function to pass as a 'BlockedContactsChanged' dbus-signal even predicate
+# checking if the @blocked and @unblocked contacts match those from the
+# signal
+def blocked_contacts_changed_predicate(e, blocked, unblocked):
+    b, u = e.args
+
+    return set(b.values()) == set(blocked) and set(u.values()) == set(unblocked)
+
+# function to pass as a 'GroupsCreated' dbus-signal even predicate
+# checking if the created @groups match those from the signal
+def groups_created_predicate(e, groups):
+    return set(e.args[0]) == set(groups)
+
+# function to pass as a 'GroupsChanged' dbus-signal even predicate
+# checking if @contacts have been added/removed to/from the @added/@removed
+# groups
+def groups_changed_predicate(e, conn, contacts, added, removed):
+    c, a, r = e.args
+    handles = conn.get_contact_handles_sync(contacts)
+
+    return set(handles) == set(c) and set(added) == set(a) and set(removed) == set(r)



More information about the telepathy-commits mailing list