[telepathy-idle/master] Advertise the Requests interface, add test

Jonathon Jongsma jonathon.jongsma at collabora.co.uk
Thu Sep 10 16:07:39 PDT 2009


Borrow a test from gabble for Requests.CreateChannel and modify it to fit idle.
This is just a very cursory test fo the Requests interface.
---
 src/idle-connection.c                     |    1 +
 tests/twisted/Makefile.am                 |    1 +
 tests/twisted/channels/requests-create.py |   83 +++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 0 deletions(-)
 create mode 100644 tests/twisted/channels/requests-create.py

diff --git a/src/idle-connection.c b/src/idle-connection.c
index 1664c91..273ec62 100644
--- a/src/idle-connection.c
+++ b/src/idle-connection.c
@@ -347,6 +347,7 @@ static void idle_connection_class_init(IdleConnectionClass *klass) {
 	static const gchar *interfaces_always_present[] = {
 		TP_IFACE_CONNECTION_INTERFACE_ALIASING,
 		IDLE_IFACE_CONNECTION_INTERFACE_RENAMING,
+		TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
 		NULL};
 
 	g_type_class_add_private(klass, sizeof(IdleConnectionPrivate));
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 7b1d3b0..47fc589 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -4,6 +4,7 @@ TWISTED_TESTS = \
 		connect/connect-fail.py \
 		connect/connect-fail-ssl.py \
 		channels/join-muc-channel.py \
+		channels/requests-create.py \
 		messages/message-order.py \
 		messages/leading-space.py \
 		$(NULL)
diff --git a/tests/twisted/channels/requests-create.py b/tests/twisted/channels/requests-create.py
new file mode 100644
index 0000000..2dd97d8
--- /dev/null
+++ b/tests/twisted/channels/requests-create.py
@@ -0,0 +1,83 @@
+
+"""
+Test creating a channel with the Requests interface
+Most of this test was borrowed from a gabble test and modified to fit idle
+"""
+
+from idletest import exec_test
+from servicetest import EventPattern, call_async, tp_name_prefix
+import dbus
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[0,1])
+
+    nick = 'foo'
+    call_async(q, conn, 'RequestHandles', 1, [nick])
+    event = q.expect('dbus-return', method='RequestHandles')
+    foo_handle = event.value[0][0]
+
+    properties = conn.GetAll(
+            'org.freedesktop.Telepathy.Connection.Interface.Requests',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert properties.get('Channels') == [], properties['Channels']
+    assert ({'org.freedesktop.Telepathy.Channel.ChannelType':
+                'org.freedesktop.Telepathy.Channel.Type.Text',
+             'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
+             },
+             ['org.freedesktop.Telepathy.Channel.TargetHandle',
+              'org.freedesktop.Telepathy.Channel.TargetID'
+             ],
+             ) in properties.get('RequestableChannelClasses'),\
+                     properties['RequestableChannelClasses']
+
+    requestotron = dbus.Interface(conn,
+            'org.freedesktop.Telepathy.Connection.Interface.Requests')
+    call_async(q, requestotron, 'CreateChannel',
+            { 'org.freedesktop.Telepathy.Channel.ChannelType':
+                'org.freedesktop.Telepathy.Channel.Type.Text',
+              'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
+              'org.freedesktop.Telepathy.Channel.TargetHandle': foo_handle,
+              })
+
+    ret, old_sig, new_sig = q.expect_many(
+        EventPattern('dbus-return', method='CreateChannel'),
+        EventPattern('dbus-signal', signal='NewChannel'),
+        EventPattern('dbus-signal', signal='NewChannels'),
+        )
+
+    assert len(ret.value) == 2
+    emitted_props = ret.value[1]
+    assert emitted_props['org.freedesktop.Telepathy.Channel.ChannelType'] ==\
+            'org.freedesktop.Telepathy.Channel.Type.Text'
+    assert emitted_props['org.freedesktop.Telepathy.Channel.'
+            'TargetHandleType'] == 1
+    assert emitted_props['org.freedesktop.Telepathy.Channel.TargetHandle'] ==\
+            foo_handle
+
+    assert old_sig.args[0] == ret.value[0]
+    assert old_sig.args[1] == u'org.freedesktop.Telepathy.Channel.Type.Text'
+    # check that handle type == contact handle
+    assert old_sig.args[2] == 1
+    assert old_sig.args[3] == foo_handle
+    assert old_sig.args[4] == True      # suppress handler
+
+    assert len(new_sig.args) == 1
+    assert len(new_sig.args[0]) == 1        # one channel
+    assert len(new_sig.args[0][0]) == 2     # two struct members
+    assert new_sig.args[0][0][0] == ret.value[0]
+    assert new_sig.args[0][0][1] == ret.value[1]
+
+    properties = conn.GetAll(
+            'org.freedesktop.Telepathy.Connection.Interface.Requests',
+            dbus_interface='org.freedesktop.DBus.Properties')
+
+    assert new_sig.args[0][0] in properties['Channels'], \
+            (new_sig.args[0][0], properties['Channels'])
+
+    call_async(q, conn, 'Disconnect')
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+
+if __name__ == "__main__":
+    exec_test(test)
-- 
1.5.6.5




More information about the telepathy-commits mailing list