[Telepathy-commits] [telepathy-haze/master] Import three more tests from Gabble.
Will Thompson
will.thompson at collabora.co.uk
Sun Mar 22 03:40:02 PDT 2009
---
tests/twisted/Makefile.am | 6 +-
tests/twisted/text/ensure.py | 199 +++++++++++++++++++++++++++
tests/twisted/text/initiate-requestotron.py | 99 +++++++++++++
tests/twisted/text/test-text-no-body.py | 42 ++++++
4 files changed, 345 insertions(+), 1 deletions(-)
create mode 100644 tests/twisted/text/ensure.py
create mode 100644 tests/twisted/text/initiate-requestotron.py
create mode 100644 tests/twisted/text/test-text-no-body.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index dabf44e..549147b 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -2,7 +2,11 @@ TWISTED_TESTS = \
connect/success.py \
connect/fail.py \
presence/presence.py \
- text/initiate.py
+ text/ensure.py \
+ text/initiate-requestotron.py \
+ text/initiate.py \
+ text/test-text-no-body.py
+
TESTS =
diff --git a/tests/twisted/text/ensure.py b/tests/twisted/text/ensure.py
new file mode 100644
index 0000000..ee303e8
--- /dev/null
+++ b/tests/twisted/text/ensure.py
@@ -0,0 +1,199 @@
+"""
+Test text channel initiated by me, using Requests.EnsureChannel
+"""
+
+import dbus
+
+from twisted.words.xish import domish
+
+from hazetest import exec_test
+from servicetest import call_async, EventPattern, unwrap
+
+import pprint
+
+import constants as cs
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ self_handle = conn.GetSelfHandle()
+
+ jids = ['foo at bar.com', 'truc at cafe.fr']
+ call_async(q, conn, 'RequestHandles', 1, jids)
+
+ event = q.expect('dbus-return', method='RequestHandles')
+ handles = event.value[0]
+
+ properties = conn.GetAll(
+ 'org.freedesktop.Telepathy.Connection.Interface.Requests',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ # Difference from Gabble: Haze's roster channels spring to life even if you
+ # haven't received the XMPP roster.
+ text_channels = [c for c in properties.get('Channels')
+ if c[1][cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT
+ ]
+ assert text_channels == [], text_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']
+
+ test_ensure_ensure(q, conn, self_handle, jids[0], handles[0])
+ test_request_ensure(q, conn, self_handle, jids[1], handles[1])
+
+ conn.Disconnect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+
+def test_ensure_ensure(q, conn, self_handle, jid, handle):
+ """
+ Test ensuring a non-existant channel twice. The first call should succeed
+ with Yours=True; the subsequent call should succeed with Yours=False
+ """
+
+ # Check that Ensuring a channel that doesn't exist succeeds
+ call_async(q, conn.Requests, 'EnsureChannel', request_props (handle))
+
+ ret, old_sig, new_sig = q.expect_many(
+ EventPattern('dbus-return', method='EnsureChannel'),
+ EventPattern('dbus-signal', signal='NewChannel'),
+ EventPattern('dbus-signal', signal='NewChannels'),
+ )
+
+ assert len(ret.value) == 3
+ yours, path, emitted_props = ret.value
+
+ # The channel was created in response to the call, and we were the only
+ # requestor, so we should get Yours=True
+ assert yours, 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=dbus.PROPERTIES_IFACE)
+
+ assert new_sig.args[0][0] in properties['Channels'], \
+ (new_sig.args[0][0], properties['Channels'])
+
+
+ # Now try Ensuring a channel which already exists
+ call_async(q, conn.Requests, '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, 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, conn.Requests, '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=dbus.PROPERTIES_IFACE)
+
+ 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, conn.Requests, '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 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.'
+ 'Requested'] == True
+ assert props['org.freedesktop.Telepathy.Channel.'
+ 'InitiatorHandle'] == self_handle
+ assert props['org.freedesktop.Telepathy.Channel.'
+ '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)
+
diff --git a/tests/twisted/text/initiate-requestotron.py b/tests/twisted/text/initiate-requestotron.py
new file mode 100644
index 0000000..867f6c0
--- /dev/null
+++ b/tests/twisted/text/initiate-requestotron.py
@@ -0,0 +1,99 @@
+"""
+Test text channel initiated by me, using Requests.
+"""
+
+import dbus
+
+from twisted.words.xish import domish
+
+from hazetest import exec_test
+from servicetest import call_async, EventPattern
+
+import constants as cs
+
+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]
+
+ properties = conn.GetAll(
+ 'org.freedesktop.Telepathy.Connection.Interface.Requests',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ # Difference from Gabble: Haze's roster channels spring to life even if you
+ # haven't received the XMPP roster.
+ text_channels = [c for c in properties.get('Channels')
+ if c[1][cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT
+ ]
+ assert text_channels == [], text_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']
+
+ call_async(q, conn.Requests, '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 emitted_props['org.freedesktop.Telepathy.Channel.TargetID'] == jid
+ assert emitted_props['org.freedesktop.Telepathy.Channel.'
+ 'Requested'] == True
+ assert emitted_props['org.freedesktop.Telepathy.Channel.'
+ 'InitiatorHandle'] == self_handle
+ assert emitted_props['org.freedesktop.Telepathy.Channel.'
+ 'InitiatorID'] == 'test at localhost'
+
+ 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=dbus.PROPERTIES_IFACE)
+
+ assert new_sig.args[0][0] in properties['Channels'], \
+ (new_sig.args[0][0], properties['Channels'])
+
+ conn.Disconnect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+if __name__ == '__main__':
+ exec_test(test)
+
diff --git a/tests/twisted/text/test-text-no-body.py b/tests/twisted/text/test-text-no-body.py
new file mode 100644
index 0000000..5de00c2
--- /dev/null
+++ b/tests/twisted/text/test-text-no-body.py
@@ -0,0 +1,42 @@
+
+"""
+Test that <message>s with a chat state notification but no body don't create a
+new text channel.
+"""
+
+from twisted.words.xish import domish
+
+from hazetest import exec_test
+
+import ns
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ # message without body
+ m = domish.Element((None, 'message'))
+ m['from'] = 'alice at foo.com'
+ m['type'] = 'chat'
+ m.addElement((ns.CHAT_STATES, 'composing'))
+ stream.send(m)
+
+ # message with body
+ m = domish.Element((None, 'message'))
+ m['from'] = 'bob at foo.com'
+ m['type'] = 'chat'
+ m.addElement((ns.CHAT_STATES, 'active'))
+ m.addElement('body', content='hello')
+ stream.send(m)
+
+ # first message should be from Bob, not Alice
+ event = q.expect('dbus-signal', signal='NewChannel')
+ assert event.args[1] == u'org.freedesktop.Telepathy.Channel.Type.Text'
+ jid = conn.InspectHandles(1, [event.args[3]])[0]
+ assert jid == 'bob at foo.com'
+ 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