summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2012-05-01 11:07:00 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2012-05-01 11:07:00 +0100
commite851e224d7a733acc67f031c8c3b900e78d7dea5 (patch)
tree03b7229a38dae2ae39e7f5a8acaa50c954c62dbc
parent04909550618339a33f6a5b40ac5e6176ca280972 (diff)
tests: add simple test to ensure ContactCapabilities are working
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--tests/twisted/Makefile.am1
-rw-r--r--tests/twisted/simple-caps.py74
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@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@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@foo.com'])[0]
+ check_rccs(conn, amy_handle)
+
+if __name__ == '__main__':
+ exec_test(test_self_handle)
+ exec_test(test_someone_else)
+