[Telepathy-commits] [telepathy-gabble/master] text/initiate.py: new test to check that we can initiate 1-1 text channels

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Aug 19 10:53:26 PDT 2008


20080721145811-53eee-3050c4d6d624e4236c3b654f6edad81a80e940f5.gz
---
 tests/twisted/Makefile.am      |    1 +
 tests/twisted/text/initiate.py |  102 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 tests/twisted/text/initiate.py

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 3b126a0..a2ea7d5 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -13,6 +13,7 @@ TWISTED_TESTS = \
 	roster/test-google-roster.py \
 	roster/test-roster.py \
 	roster/test-roster-subscribe.py \
+	text/initiate.py \
 	text/test-text-delayed.py \
 	text/test-text-no-body.py \
 	text/test-text.py \
diff --git a/tests/twisted/text/initiate.py b/tests/twisted/text/initiate.py
new file mode 100644
index 0000000..926dbb9
--- /dev/null
+++ b/tests/twisted/text/initiate.py
@@ -0,0 +1,102 @@
+"""
+Test text channel initiated by me.
+"""
+
+import dbus
+
+from twisted.words.xish import domish
+
+from gabbletest 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]
+    assert sig.args[1] == u'org.freedesktop.Telepathy.Channel.Type.Text'
+    # check that handle type == contact handle
+    assert sig.args[2] == 1
+    assert 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='org.freedesktop.DBus.Properties')
+    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 'org.freedesktop.Telepathy.Channel.FUTURE' in \
+            channel_props.get('Interfaces', ()), \
+            channel_props.get('Interfaces')
+
+    future_props = text_chan.GetAll(
+            'org.freedesktop.Telepathy.Channel.FUTURE',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert future_props['TargetID'] == jid,\
+            (future_props['TargetID'], jid)
+    assert future_props['InitiatorHandle'] == self_handle,\
+            (future_props['InitiatorHandle'], self_handle)
+    assert future_props['InitiatorID'] == 'test at localhost',\
+            future_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(('', '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.3




More information about the Telepathy-commits mailing list