[Telepathy-commits] [telepathy-gabble/master] IM channels: Test Create-then-Ensure as well as Ensure-then-Ensure

Will Thompson will.thompson at collabora.co.uk
Wed Sep 24 08:06:48 PDT 2008


---
 tests/twisted/text/ensure-requestotron.py |  112 ++++++++++++++++++++++-------
 1 files changed, 86 insertions(+), 26 deletions(-)

diff --git a/tests/twisted/text/ensure-requestotron.py b/tests/twisted/text/ensure-requestotron.py
index c23c3c6..cb68c16 100644
--- a/tests/twisted/text/ensure-requestotron.py
+++ b/tests/twisted/text/ensure-requestotron.py
@@ -39,6 +39,7 @@ def test(q, bus, conn, stream):
             'org.freedesktop.Telepathy.Connection.Interface.Requests')
 
     test_ensure_ensure(q, requestotron, conn, self_handle, jids[0], handles[0])
+    test_request_ensure(q, requestotron, conn, self_handle, jids[1], handles[1])
 
     conn.Disconnect()
     q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
@@ -51,12 +52,7 @@ def test_ensure_ensure(q, requestotron, conn, self_handle, jid, handle):
     """
 
     # Check that Ensuring a channel that doesn't exist succeeds
-    call_async(q, requestotron, 'EnsureChannel',
-            { 'org.freedesktop.Telepathy.Channel.ChannelType':
-                'org.freedesktop.Telepathy.Channel.Type.Text',
-              'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
-              'org.freedesktop.Telepathy.Channel.TargetHandle': handle,
-              })
+    call_async(q, requestotron, 'EnsureChannel', request_props (handle))
 
     ret, old_sig, new_sig = q.expect_many(
         EventPattern('dbus-return', method='EnsureChannel'),
@@ -71,19 +67,7 @@ def test_ensure_ensure(q, requestotron, conn, self_handle, jid, handle):
     # requestor, so we should get Yours=True
     assert yours, ret.value
 
-    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'] ==\
-            handle
-    assert emitted_props['org.freedesktop.Telepathy.Channel.TargetID'] == jid
-    assert emitted_props['org.freedesktop.Telepathy.Channel.FUTURE.'
-            'Requested'] == True
-    assert emitted_props['org.freedesktop.Telepathy.Channel.FUTURE.'
-            'InitiatorHandle'] == self_handle
-    assert emitted_props['org.freedesktop.Telepathy.Channel.FUTURE.'
-            'InitiatorID'] == 'test at localhost'
+    check_props(emitted_props, self_handle, handle, jid)
 
     assert len(old_sig.args) == 5
     old_path, old_ct, old_ht, old_h, old_sh = old_sig.args
@@ -93,7 +77,7 @@ def test_ensure_ensure(q, requestotron, conn, self_handle, jid, handle):
     # check that handle type == contact handle
     assert old_ht == 1
     assert old_h == handle
-    # assert old_sh == True      # suppress handler
+    assert old_sh == True      # suppress handler
 
     assert len(new_sig.args) == 1
     assert len(new_sig.args[0]) == 1        # one channel
@@ -110,12 +94,64 @@ def test_ensure_ensure(q, requestotron, conn, self_handle, jid, handle):
 
 
     # Now try Ensuring a channel which already exists
-    call_async(q, requestotron, 'EnsureChannel',
-            { 'org.freedesktop.Telepathy.Channel.ChannelType':
-                'org.freedesktop.Telepathy.Channel.Type.Text',
-              'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
-              'org.freedesktop.Telepathy.Channel.TargetHandle': handle,
-              })
+    call_async(q, requestotron, 'EnsureChannel', request_props (handle))
+    ret_ = q.expect('dbus-return', method='EnsureChannel')
+
+    assert len(ret_.value) == 3
+    yours_, path_, emitted_props_ = ret_.value
+
+    # Someone's already responsible for this channel, so we should get
+    # Yours=False
+    assert not yours_, ret_.value
+    assert path == path_, (path, path_)
+    assert emitted_props == emitted_props_, (emitted_props, emitted_props_)
+
+
+def test_request_ensure(q, requestotron, conn, self_handle, jid, handle):
+    """
+    Test Creating a non-existant channel, then Ensuring the same channel.
+    The call to Ensure should succeed with Yours=False.
+    """
+
+    call_async(q, requestotron, 'CreateChannel', request_props (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
+    path, emitted_props = ret.value
+
+    check_props(emitted_props, self_handle, handle, jid)
+
+    assert len(old_sig.args) == 5
+    old_path, old_ct, old_ht, old_h, old_sh = old_sig.args
+
+    assert old_path == path
+    assert old_ct == u'org.freedesktop.Telepathy.Channel.Type.Text'
+    # check that handle type == contact handle
+    assert old_ht == 1
+    assert old_h == handle
+    assert old_sh == 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] == path
+    assert new_sig.args[0][0][1] == emitted_props
+
+    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'])
+
+
+    # Now try Ensuring that same channel.
+    call_async(q, requestotron, 'EnsureChannel', request_props (handle))
     ret_ = q.expect('dbus-return', method='EnsureChannel')
 
     assert len(ret_.value) == 3
@@ -128,6 +164,30 @@ def test_ensure_ensure(q, requestotron, conn, self_handle, jid, handle):
     assert emitted_props == emitted_props_, (emitted_props, emitted_props_)
 
 
+def check_props(props, self_handle, handle, jid):
+    assert props['org.freedesktop.Telepathy.Channel.ChannelType'] ==\
+            'org.freedesktop.Telepathy.Channel.Type.Text'
+    assert props['org.freedesktop.Telepathy.Channel.'
+            'TargetHandleType'] == 1
+    assert props['org.freedesktop.Telepathy.Channel.TargetHandle'] ==\
+            handle
+    assert props['org.freedesktop.Telepathy.Channel.TargetID'] == jid
+    assert props['org.freedesktop.Telepathy.Channel.FUTURE.'
+            'Requested'] == True
+    assert props['org.freedesktop.Telepathy.Channel.FUTURE.'
+            'InitiatorHandle'] == self_handle
+    assert props['org.freedesktop.Telepathy.Channel.FUTURE.'
+            'InitiatorID'] == 'test at localhost'
+
+
+def request_props(handle):
+    return { 'org.freedesktop.Telepathy.Channel.ChannelType':
+                'org.freedesktop.Telepathy.Channel.Type.Text',
+             'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
+             'org.freedesktop.Telepathy.Channel.TargetHandle': handle,
+           }
+
+
 if __name__ == '__main__':
     exec_test(test)
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list