[Telepathy-commits] [telepathy-haze/master] Copy text/initiate.py from Gabble.

Will Thompson will.thompson at collabora.co.uk
Tue Mar 24 05:21:35 PDT 2009


---
 tests/twisted/Makefile.am      |    3 +-
 tests/twisted/text/initiate.py |   98 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 1 deletions(-)
 create mode 100644 tests/twisted/text/initiate.py

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index adf7c49..fbca66b 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -1,6 +1,7 @@
 TWISTED_TESTS = \
 	connect/success.py \
-	connect/fail.py
+	connect/fail.py \
+	text/initiate.py
 
 TESTS =
 
diff --git a/tests/twisted/text/initiate.py b/tests/twisted/text/initiate.py
new file mode 100644
index 0000000..1552091
--- /dev/null
+++ b/tests/twisted/text/initiate.py
@@ -0,0 +1,98 @@
+"""
+Test text channel initiated by me.
+"""
+
+import dbus
+
+from twisted.words.xish import domish
+
+from hazetest import exec_test
+from servicetest import call_async, EventPattern
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+    self_handle = conn.GetSelfHandle()
+
+    jid = 'foo at bar.com'
+    call_async(q, conn, 'RequestHandles', 1, [jid])
+
+    event = q.expect('dbus-return', method='RequestHandles')
+    foo_handle = event.value[0][0]
+
+    call_async(q, conn, 'RequestChannel',
+        'org.freedesktop.Telepathy.Channel.Type.Text', 1, foo_handle, True)
+
+    ret, sig = q.expect_many(
+        EventPattern('dbus-return', method='RequestChannel'),
+        EventPattern('dbus-signal', signal='NewChannel'),
+        )
+
+    text_chan = bus.get_object(conn.bus_name, ret.value[0])
+
+    assert sig.args[0] == ret.value[0], \
+            (sig.args[0], ret.value[0])
+    assert sig.args[1] == u'org.freedesktop.Telepathy.Channel.Type.Text',\
+            sig.args[1]
+    # check that handle type == contact handle
+    assert sig.args[2] == 1, sig.args[1]
+    assert sig.args[3] == foo_handle, (sig.args[3], foo_handle)
+    assert sig.args[4] == True      # suppress handler
+
+    # Exercise basic Channel Properties from spec 0.17.7
+    channel_props = text_chan.GetAll(
+            'org.freedesktop.Telepathy.Channel',
+            dbus_interface=dbus.PROPERTIES_IFACE)
+    assert channel_props.get('TargetHandle') == foo_handle,\
+            (channel_props.get('TargetHandle'), foo_handle)
+    assert channel_props.get('TargetHandleType') == 1,\
+            channel_props.get('TargetHandleType')
+    assert channel_props.get('ChannelType') == \
+            'org.freedesktop.Telepathy.Channel.Type.Text',\
+            channel_props.get('ChannelType')
+    assert 'org.freedesktop.Telepathy.Channel.Interface.ChatState' in \
+            channel_props.get('Interfaces', ()), \
+            channel_props.get('Interfaces')
+    assert channel_props['TargetID'] == jid,\
+            (channel_props['TargetID'], jid)
+    assert channel_props['Requested'] == True
+    assert channel_props['InitiatorHandle'] == self_handle,\
+            (channel_props['InitiatorHandle'], self_handle)
+    assert channel_props['InitiatorID'] == 'test at localhost',\
+            channel_props['InitiatorID']
+
+    dbus.Interface(text_chan,
+        u'org.freedesktop.Telepathy.Channel.Type.Text').Send(0, 'hey')
+
+    event = q.expect('stream-message')
+
+    elem = event.stanza
+    assert elem.name == 'message'
+    assert elem['type'] == 'chat'
+    body = list(event.stanza.elements())[0]
+    assert body.name == 'body'
+    assert body.children[0] == u'hey'
+
+    # <message type="chat"><body>hello</body</message>
+    m = domish.Element((None, 'message'))
+    m['from'] = 'foo at bar.com/Pidgin'
+    m['type'] = 'chat'
+    m.addElement('body', content='hello')
+    stream.send(m)
+
+    event = q.expect('dbus-signal', signal='Received')
+
+    # message type: normal
+    assert event.args[3] == 0
+    # flags: none
+    assert event.args[4] == 0
+    # body
+    assert event.args[5] == 'hello'
+
+    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