telepathy-haze: tests: add simple test to ensure ContactCapabilities are working

Jonny Lamb jonny at kemper.freedesktop.org
Wed May 2 06:32:01 PDT 2012


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

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Tue May  1 11:07:00 2012 +0100

tests: add simple test to ensure ContactCapabilities are working

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>

---

 tests/twisted/Makefile.am    |    1 +
 tests/twisted/simple-caps.py |   74 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index f8e1fe2..3f89664 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -1,5 +1,6 @@
 TWISTED_TESTS = \
 	avatar-requirements.py \
+	simple-caps.py \
 	cm/protocols.py \
 	connect/fail.py \
 	connect/success.py \
diff --git a/tests/twisted/simple-caps.py b/tests/twisted/simple-caps.py
new file mode 100644
index 0000000..519d0bd
--- /dev/null
+++ b/tests/twisted/simple-caps.py
@@ -0,0 +1,74 @@
+
+"""
+Make sure ContactCaps works well enough.
+"""
+
+from twisted.words.xish import domish
+
+from servicetest import assertEquals, assertContains, EventPattern
+from hazetest import exec_test
+import constants as cs
+
+import ns
+
+# assert this list of RCCs is only text
+def check_text_only(rccs):
+    assertEquals([({
+                cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
+                cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT
+                }, [cs.TARGET_HANDLE])], rccs)
+
+# assert GetContactCaps and GetContactAttributes returns just text caps
+def check_rccs(conn, handle):
+    rccs = conn.ContactCapabilities.GetContactCapabilities([handle])
+    assertEquals(1, len(rccs))
+    check_text_only(rccs[handle])
+
+    attrs = conn.Contacts.GetContactAttributes([handle],
+                                               [cs.CONN_IFACE_CONTACT_CAPS],
+                                               False)
+    rccs = attrs[handle][cs.CONN_IFACE_CONTACT_CAPS + '/capabilities']
+    check_text_only(rccs)
+
+# do the self handle which will just be text
+def test_self_handle(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged',
+             args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+    self_handle = conn.Properties.Get(cs.CONN, 'SelfHandle')
+
+    check_rccs(conn, self_handle)
+
+# do someone else which will also just be text
+def test_someone_else(q, bus, conn, stream):
+    conn.Connect()
+    q.expect_many(
+            EventPattern('dbus-signal', signal='StatusChanged',
+                args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED]),
+            EventPattern('stream-authenticated'),
+            )
+
+    event = q.expect('stream-iq', query_ns=ns.ROSTER)
+    event.stanza['type'] = 'result'
+
+    item = event.query.addElement('item')
+    item['jid'] = 'bob at foo.com'
+    item['subscription'] = 'both'
+
+    stream.send(event.stanza)
+
+    q.expect('dbus-signal', signal='StatusChanged',
+            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+    bob_handle = conn.RequestHandles(cs.HT_CONTACT, ['bob at foo.com'])[0]
+    check_rccs(conn, bob_handle)
+
+    # now a randomer who isn't even in our contact list
+    amy_handle = conn.RequestHandles(cs.HT_CONTACT, ['amy at foo.com'])[0]
+    check_rccs(conn, amy_handle)
+
+if __name__ == '__main__':
+    exec_test(test_self_handle)
+    exec_test(test_someone_else)
+



More information about the telepathy-commits mailing list