From 1e8abae52426bab3dc5aa014261d4b3847e95fcc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 25 Sep 2013 15:11:24 +0100 Subject: [PATCH] Text tests: use the Messages interface This makes them more like the ones in 'next', which use the newly unified Text interface (whose API is mostly based on Messages). --- tests/twisted/text/destroy.py | 43 ++++++++++++++----------- tests/twisted/text/respawn.py | 57 ++++++++++++++++++--------------- tests/twisted/text/test-text-delayed.py | 9 +----- tests/twisted/text/test-text.py | 38 ++++++---------------- 4 files changed, 65 insertions(+), 82 deletions(-) diff --git a/tests/twisted/text/destroy.py b/tests/twisted/text/destroy.py index bb31c8f..9e0a03c 100644 --- a/tests/twisted/text/destroy.py +++ b/tests/twisted/text/destroy.py @@ -8,7 +8,8 @@ import dbus from twisted.words.xish import domish from hazetest import exec_test -from servicetest import call_async, EventPattern, assertEquals, assertLength +from servicetest import (call_async, EventPattern, assertEquals, assertLength, + assertContains) import constants as cs def test(q, bus, conn, stream): @@ -31,6 +32,7 @@ def test(q, bus, conn, stream): text_chan = bus.get_object(conn.bus_name, ret.value[0]) chan_iface = dbus.Interface(text_chan, cs.CHANNEL) text_iface = dbus.Interface(text_chan, cs.CHANNEL_TYPE_TEXT) + messages_iface = dbus.Interface(text_chan, cs.CHANNEL_IFACE_MESSAGES) destroyable_iface = dbus.Interface(text_chan, cs.CHANNEL_IFACE_DESTROYABLE) assertLength(1, sig.args) @@ -45,6 +47,8 @@ def test(q, bus, conn, stream): assertEquals(True, emitted_props[cs.REQUESTED]) assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE]) assertEquals('test@localhost', emitted_props[cs.INITIATOR_ID]) + assertContains(cs.CHANNEL_IFACE_MESSAGES, emitted_props[cs.INTERFACES]) + assertContains(cs.CHANNEL_IFACE_DESTROYABLE, emitted_props[cs.INTERFACES]) channel_props = text_chan.GetAll(cs.CHANNEL, dbus_interface=dbus.PROPERTIES_IFACE) @@ -56,7 +60,10 @@ def test(q, bus, conn, stream): assert channel_props['InitiatorID'] == 'test@localhost',\ channel_props['InitiatorID'] - text_iface.Send(0, 'hey') + messages_iface.SendMessage([{}, { + 'content-type': 'text/plain', + 'content': 'hey', + }], 0) event = q.expect('stream-message') @@ -79,23 +86,21 @@ def test(q, bus, conn, stream): m.addElement('body', content='hello') stream.send(m) - event = q.expect('dbus-signal', signal='Received') - - hello_message_id = event.args[0] - hello_message_time = event.args[1] - assert event.args[2] == foo_handle - # message type: normal - assert event.args[3] == 0 - # flags: none - assert event.args[4] == 0 - # body - assert event.args[5] == 'hello' - - messages = text_chan.ListPendingMessages(False, - dbus_interface=cs.CHANNEL_TYPE_TEXT) - assert messages == \ - [(hello_message_id, hello_message_time, foo_handle, - 0, 0, 'hello')], messages + event = q.expect('dbus-signal', signal='MessageReceived') + + message = event.args[0] + assertLength(2, message) + hello_message_id = message[0]['pending-message-id'] + assertEquals(foo_handle, message[0]['message-sender']) + assertEquals('foo@bar.com', message[0]['message-sender-id']) + assertEquals(cs.MT_NORMAL, + message[0].get('message-type', cs.MT_NORMAL)) + assertEquals('text/plain', message[1]['content-type']) + assertEquals('hello', message[1]['content']) + + messages = text_chan.Get(cs.CHANNEL_IFACE_MESSAGES, 'PendingMessages', + dbus_interface=cs.PROPERTIES_IFACE) + assertEquals([message], messages) # destroy the channel without acking the message; it does not come back diff --git a/tests/twisted/text/respawn.py b/tests/twisted/text/respawn.py index 170c331..e86b6c4 100644 --- a/tests/twisted/text/respawn.py +++ b/tests/twisted/text/respawn.py @@ -7,7 +7,8 @@ import dbus from twisted.words.xish import domish from hazetest import exec_test -from servicetest import call_async, EventPattern, assertEquals, assertLength +from servicetest import (call_async, EventPattern, assertEquals, assertLength, + assertContains) import constants as cs def test(q, bus, conn, stream): @@ -30,6 +31,8 @@ def test(q, bus, conn, stream): text_chan = bus.get_object(conn.bus_name, ret.value[0]) chan_iface = dbus.Interface(text_chan, cs.CHANNEL) text_iface = dbus.Interface(text_chan, cs.CHANNEL_TYPE_TEXT) + messages_iface = dbus.Interface(text_chan, cs.CHANNEL_IFACE_MESSAGES) + destroyable_iface = dbus.Interface(text_chan, cs.CHANNEL_IFACE_DESTROYABLE) assertLength(1, sig.args) assertLength(1, sig.args[0]) # one channel @@ -43,6 +46,8 @@ def test(q, bus, conn, stream): assertEquals(True, emitted_props[cs.REQUESTED]) assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE]) assertEquals('test@localhost', emitted_props[cs.INITIATOR_ID]) + assertContains(cs.CHANNEL_IFACE_MESSAGES, emitted_props[cs.INTERFACES]) + assertContains(cs.CHANNEL_IFACE_DESTROYABLE, emitted_props[cs.INTERFACES]) channel_props = text_chan.GetAll(cs.CHANNEL, dbus_interface=dbus.PROPERTIES_IFACE) @@ -54,7 +59,10 @@ def test(q, bus, conn, stream): assert channel_props['InitiatorID'] == 'test@localhost',\ channel_props['InitiatorID'] - text_iface.Send(0, 'hey') + messages_iface.SendMessage([{}, { + 'content-type': 'text/plain', + 'content': 'hey', + }], 0) event = q.expect('stream-message') @@ -77,23 +85,21 @@ def test(q, bus, conn, stream): m.addElement('body', content='hello') stream.send(m) - event = q.expect('dbus-signal', signal='Received') + event = q.expect('dbus-signal', signal='MessageReceived') - hello_message_id = event.args[0] - hello_message_time = event.args[1] - assert event.args[2] == foo_handle - # message type: normal - assert event.args[3] == 0 - # flags: none - assert event.args[4] == 0 - # body - assert event.args[5] == 'hello' + message = event.args[0] + assertLength(2, message) + hello_message_id = message[0]['pending-message-id'] + assertEquals(foo_handle, message[0]['message-sender']) + assertEquals('foo@bar.com', message[0]['message-sender-id']) + assertEquals(cs.MT_NORMAL, + message[0].get('message-type', cs.MT_NORMAL)) + assertEquals('text/plain', message[1]['content-type']) + assertEquals('hello', message[1]['content']) - messages = text_chan.ListPendingMessages(False, - dbus_interface=cs.CHANNEL_TYPE_TEXT) - assert messages == \ - [(hello_message_id, hello_message_time, foo_handle, - 0, 0, 'hello')], messages + messages = text_chan.Get(cs.CHANNEL_IFACE_MESSAGES, 'PendingMessages', + dbus_interface=cs.PROPERTIES_IFACE) + assertEquals([message], messages) # close the channel without acking the message; it comes back @@ -130,22 +136,21 @@ def test(q, bus, conn, stream): assert channel_props['InitiatorID'] == 'foo@bar.com',\ channel_props['InitiatorID'] - # the message is still there + # the message is still there, but is marked as rescued now + message[0]['rescued'] = True - messages = text_chan.ListPendingMessages(False, - dbus_interface=cs.CHANNEL_TYPE_TEXT) - assert messages == \ - [(hello_message_id, hello_message_time, foo_handle, - 0, 8, 'hello')], messages + messages = text_chan.Get(cs.CHANNEL_IFACE_MESSAGES, 'PendingMessages', + dbus_interface=cs.PROPERTIES_IFACE) + assertEquals([message], messages) # acknowledge it text_chan.AcknowledgePendingMessages([hello_message_id], dbus_interface=cs.CHANNEL_TYPE_TEXT) - messages = text_chan.ListPendingMessages(False, - dbus_interface=cs.CHANNEL_TYPE_TEXT) - assert messages == [] + messages = text_chan.Get(cs.CHANNEL_IFACE_MESSAGES, 'PendingMessages', + dbus_interface=cs.PROPERTIES_IFACE) + assertEquals([], messages) # close the channel again diff --git a/tests/twisted/text/test-text-delayed.py b/tests/twisted/text/test-text-delayed.py index c7e5740..59e73d0 100644 --- a/tests/twisted/text/test-text-delayed.py +++ b/tests/twisted/text/test-text-delayed.py @@ -28,14 +28,7 @@ def test(q, bus, conn, stream): assertEquals(cs.HT_CONTACT, event.args[0][0][1][cs.TARGET_HANDLE_TYPE]) assertEquals('foo@bar.com', event.args[0][0][1][cs.TARGET_ID]) - received, message_received = q.expect_many( - EventPattern('dbus-signal', signal='Received'), - EventPattern('dbus-signal', signal='MessageReceived'), - ) - - old_signal_time = str(datetime.datetime.utcfromtimestamp(received.args[1])) - assert old_signal_time == '2007-05-17 16:15:01', old_signal_time - assert received.args[5] == 'hello' + message_received = q.expect('dbus-signal', signal='MessageReceived') message = message_received.args[0] header = message[0] diff --git a/tests/twisted/text/test-text.py b/tests/twisted/text/test-text.py index 91ebb6a..b1916ed 100644 --- a/tests/twisted/text/test-text.py +++ b/tests/twisted/text/test-text.py @@ -47,21 +47,8 @@ def test(q, bus, conn, stream): assert channel_props['InitiatorID'] == jid,\ (channel_props['InitiatorID'], jid) - received, message_received = q.expect_many( - EventPattern('dbus-signal', signal='Received'), - EventPattern('dbus-signal', signal='MessageReceived'), - ) - - # Check that C.T.Text.Received looks right - # message type: normal - assert received.args[3] == 0 - # flags: none - assert received.args[4] == 0 - # body - assert received.args[5] == 'hello' + message_received = q.expect('dbus-signal', signal='MessageReceived') - - # Check that C.I.Messages.MessageReceived looks right. message = message_received.args[0] # message should have two parts: the header and one content part @@ -92,7 +79,7 @@ def test(q, bus, conn, stream): # Send an action using the Messages API # In Gabble, this is a Notice, but we don't support those. greeting = [ - dbus.Dictionary({ 'message-type': 1, # Action + dbus.Dictionary({ 'message-type': cs.MT_ACTION, }, signature='sv'), { 'content-type': 'text/plain', 'content': u"waves", @@ -102,9 +89,8 @@ def test(q, bus, conn, stream): dbus.Interface(text_chan, cs.CHANNEL_IFACE_MESSAGES ).SendMessage(greeting, dbus.UInt32(0)) - stream_message, sent, message_sent = q.expect_many( + stream_message, message_sent = q.expect_many( EventPattern('stream-message'), - EventPattern('dbus-signal', signal='Sent'), EventPattern('dbus-signal', signal='MessageSent'), ) @@ -128,16 +114,14 @@ def test(q, bus, conn, stream): assert body['content-type'] == 'text/plain', body assert body['content'] == u'waves', body - assert sent.args[1] == 1, sent.args # Action - assert sent.args[2] == u'waves', sent.args - - - # Send a message using Channel.Type.Text API - dbus.Interface(text_chan, cs.CHANNEL_TYPE_TEXT).Send(0, 'goodbye') + dbus.Interface(text_chan, cs.CHANNEL_IFACE_MESSAGES + ).SendMessage([{}, { + 'content-type': 'text/plain', + 'content': 'goodbye', + }], 0) - stream_message, sent, message_sent = q.expect_many( + stream_message, message_sent = q.expect_many( EventPattern('stream-message'), - EventPattern('dbus-signal', signal='Sent'), EventPattern('dbus-signal', signal='MessageSent'), ) @@ -163,10 +147,6 @@ def test(q, bus, conn, stream): assert body['content-type'] == 'text/plain', body assert body['content'] == u'goodbye', body - assert sent.args[1] == 0, sent.args # message type normal - assert sent.args[2] == u'goodbye', sent.args - - conn.Disconnect() q.expect('dbus-signal', signal='StatusChanged', args=[2, 1]) -- 1.8.4.rc3