From d046de4ab84070def3ae3579dd6c5578ca34309e Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 4 Oct 2013 14:32:38 +0200 Subject: [PATCH 2/2] stop using NewChannel signal in tests --- tests/twisted/jingle/session-id-collision.py | 8 ++--- tests/twisted/muc/test-muc-invitation.py | 16 ++++----- tests/twisted/power-save.py | 2 +- tests/twisted/sasl/saslutil.py | 18 +++------- tests/twisted/test-debug.py | 6 ++-- tests/twisted/text/destroy.py | 9 +---- tests/twisted/text/ensure.py | 24 ++----------- tests/twisted/text/initiate-requestotron.py | 9 +---- tests/twisted/text/initiate.py | 15 ++++---- tests/twisted/text/respawn.py | 21 ++++------- tests/twisted/text/test-chat-state.py | 3 +- tests/twisted/text/test-text-delayed.py | 13 +++---- tests/twisted/text/test-text.py | 46 ++++++++++--------------- tests/twisted/tubes/accept-muc-stream-tube.py | 6 +--- tests/twisted/tubes/check-create-tube-return.py | 6 ++-- 15 files changed, 66 insertions(+), 136 deletions(-) diff --git a/tests/twisted/jingle/session-id-collision.py b/tests/twisted/jingle/session-id-collision.py index 724537f..b981540 100644 --- a/tests/twisted/jingle/session-id-collision.py +++ b/tests/twisted/jingle/session-id-collision.py @@ -27,14 +27,14 @@ def test(jp, q, bus, conn, stream): jt2.sid = '1' jt1.incoming_call() - q.expect('dbus-signal', signal='NewChannel', - predicate=lambda e: cs.CHANNEL_TYPE_CONTACT_LIST not in e.args) + q.expect('dbus-signal', signal='NewChannels', + predicate=lambda e: cs.CHANNEL_TYPE_CALL in e.args[0][0][1][cs.CHANNEL_TYPE]) # If Gabble confuses the two sessions, it'll NAK the IQ rather than # realising this is a new call. jt2.incoming_call() - q.expect('dbus-signal', signal='NewChannel', - predicate=lambda e: cs.CHANNEL_TYPE_CONTACT_LIST not in e.args) + q.expect('dbus-signal', signal='NewChannels', + predicate=lambda e: cs.CHANNEL_TYPE_CALL in e.args[0][0][1][cs.CHANNEL_TYPE]) # On the other hand, if the same person calls twice with the same sid, # Gabble _should_ NAK the second s-i. diff --git a/tests/twisted/muc/test-muc-invitation.py b/tests/twisted/muc/test-muc-invitation.py index a6073f2..1d5a339 100644 --- a/tests/twisted/muc/test-muc-invitation.py +++ b/tests/twisted/muc/test-muc-invitation.py @@ -5,7 +5,7 @@ Test MUC invitations. from twisted.words.xish import domish, xpath from gabbletest import exec_test, make_muc_presence -from servicetest import call_async, EventPattern, wrap_channel +from servicetest import call_async, EventPattern, wrap_channel, assertEquals import constants as cs def test(q, bus, conn, stream): @@ -21,15 +21,13 @@ def test(q, bus, conn, stream): stream.send(message) - event = q.expect('dbus-signal', signal='NewChannel') - assert event.args[1] == cs.CHANNEL_TYPE_TEXT + event = q.expect('dbus-signal', signal='NewChannels') + path, props = event.args[0][0] + assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE]) + assertEquals(cs.HT_ROOM, props[cs.TARGET_HANDLE_TYPE]) + assertEquals(1, props[cs.TARGET_HANDLE]) - assert event.args[2] == 2 # handle type - assert event.args[3] == 1 # handle - room_handle = 1 - - text_chan = wrap_channel(bus.get_object(conn.bus_name, event.args[0]), - 'Text') + text_chan = wrap_channel(bus.get_object(conn.bus_name, path), 'Text') members = text_chan.Group.GetMembers() local_pending = text_chan.Group.GetLocalPendingMembers() diff --git a/tests/twisted/power-save.py b/tests/twisted/power-save.py index b127849..28861d5 100644 --- a/tests/twisted/power-save.py +++ b/tests/twisted/power-save.py @@ -117,7 +117,7 @@ def test_local_queueing(q, bus, conn, stream): event = q.expect('dbus-signal', signal='AliasesChanged') # .. and finally the message that flushed the stanza queue - q.expect('dbus-signal', signal='NewChannel') + q.expect('dbus-signal', signal='NewChannels') sync_stream(q, stream) diff --git a/tests/twisted/sasl/saslutil.py b/tests/twisted/sasl/saslutil.py index 7d14614..fcbd8f9 100644 --- a/tests/twisted/sasl/saslutil.py +++ b/tests/twisted/sasl/saslutil.py @@ -89,22 +89,14 @@ def connect_and_get_sasl_channel(q, bus, conn): return expect_sasl_channel(q, bus, conn) def expect_sasl_channel(q, bus, conn): - old_signal, new_signal = q.expect_many( - EventPattern('dbus-signal', signal='NewChannel', - predicate=lambda e: - e.args[1] == cs.CHANNEL_TYPE_SERVER_AUTHENTICATION), - EventPattern('dbus-signal', signal='NewChannels', - predicate=lambda e: - e.args[0][0][1].get(cs.CHANNEL_TYPE) == - cs.CHANNEL_TYPE_SERVER_AUTHENTICATION), - ) - - path, type, handle_type, handle, suppress_handler = old_signal.args + new_signal = q.expect('dbus-signal', signal='NewChannels', + predicate=lambda e: e.args[0][0][1].get(cs.CHANNEL_TYPE) == + cs.CHANNEL_TYPE_SERVER_AUTHENTICATION) + + path, props = new_signal.args[0][0] chan = SaslChannelWrapper(bus.get_object(conn.bus_name, path)) assertLength(1, new_signal.args[0]) - assertEquals(path, new_signal.args[0][0][0]) - props = new_signal.args[0][0][1] assertEquals(cs.CHANNEL_IFACE_SASL_AUTH, props.get(cs.AUTH_METHOD)) return chan, props diff --git a/tests/twisted/test-debug.py b/tests/twisted/test-debug.py index 52098fc..83bf1f7 100644 --- a/tests/twisted/test-debug.py +++ b/tests/twisted/test-debug.py @@ -36,9 +36,7 @@ def test(q, bus, conn, stream): channel_path = conn.RequestChannel( cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, conn.Properties.Get(cs.CONN, "SelfHandle"), True) - q.expect_many( - EventPattern ('dbus-signal', signal='NewChannel'), - EventPattern ('dbus-signal', signal = 'NewDebugMessage')) + q.expect('dbus-signal', signal = 'NewDebugMessage') assert len(messages) > 0 @@ -54,7 +52,7 @@ def test(q, bus, conn, stream): conn.RequestChannel( cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, conn.Properties.Get(cs.CONN, "SelfHandle"), True) - q.expect('dbus-signal', signal='NewChannel') + q.expect('dbus-signal', signal='NewChannels') assertEquals (snapshot, messages) diff --git a/tests/twisted/text/destroy.py b/tests/twisted/text/destroy.py index 21510c4..da970a4 100644 --- a/tests/twisted/text/destroy.py +++ b/tests/twisted/text/destroy.py @@ -20,9 +20,8 @@ def test(q, bus, conn, stream): call_async(q, conn, 'RequestChannel', cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, foo_handle, True) - ret, old_sig, new_sig = q.expect_many( + ret, new_sig = q.expect_many( EventPattern('dbus-return', method='RequestChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) @@ -31,12 +30,6 @@ def test(q, bus, conn, stream): text_iface = dbus.Interface(text_chan, cs.CHANNEL_TYPE_TEXT) destroyable_iface = dbus.Interface(text_chan, cs.CHANNEL_IFACE_DESTROYABLE) - assert old_sig.args[0] == ret.value[0] - assert old_sig.args[1] == cs.CHANNEL_TYPE_TEXT - assert old_sig.args[2] == cs.HT_CONTACT - 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 diff --git a/tests/twisted/text/ensure.py b/tests/twisted/text/ensure.py index 9cd017f..fcef90a 100644 --- a/tests/twisted/text/ensure.py +++ b/tests/twisted/text/ensure.py @@ -36,9 +36,8 @@ def test_ensure_ensure(q, conn, self_handle, jid, handle): # 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( + ret, new_sig = q.expect_many( EventPattern('dbus-return', method='EnsureChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) @@ -51,15 +50,6 @@ def test_ensure_ensure(q, conn, self_handle, jid, handle): 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 == cs.CHANNEL_TYPE_TEXT - assert old_ht == cs.HT_CONTACT - 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 @@ -95,9 +85,8 @@ def test_request_ensure(q, conn, self_handle, jid, handle): call_async(q, conn.Requests, 'CreateChannel', request_props(handle)) - ret, old_sig, new_sig = q.expect_many( + ret, new_sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) @@ -106,15 +95,6 @@ def test_request_ensure(q, conn, self_handle, jid, handle): 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 == cs.CHANNEL_TYPE_TEXT - assert old_ht == cs.HT_CONTACT - 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 diff --git a/tests/twisted/text/initiate-requestotron.py b/tests/twisted/text/initiate-requestotron.py index da2184d..c969eaa 100644 --- a/tests/twisted/text/initiate-requestotron.py +++ b/tests/twisted/text/initiate-requestotron.py @@ -31,9 +31,8 @@ def test(q, bus, conn, stream): cs.TARGET_HANDLE: foo_handle, }) - ret, old_sig, new_sig = q.expect_many( + ret, new_sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) @@ -51,12 +50,6 @@ def test(q, bus, conn, stream): assertEquals(cs.DELIVERY_REPORTING_SUPPORT_FLAGS_RECEIVE_FAILURES, emitted_props[cs.DELIVERY_REPORTING_SUPPORT]) - assert old_sig.args[0] == ret.value[0] - assert old_sig.args[1] == cs.CHANNEL_TYPE_TEXT - assert old_sig.args[2] == cs.HT_CONTACT - 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 diff --git a/tests/twisted/text/initiate.py b/tests/twisted/text/initiate.py index 5fed9e9..780bcc7 100644 --- a/tests/twisted/text/initiate.py +++ b/tests/twisted/text/initiate.py @@ -7,7 +7,7 @@ import dbus from twisted.words.xish import domish from gabbletest import exec_test -from servicetest import call_async, EventPattern +from servicetest import call_async, EventPattern, assertEquals import constants as cs def test(q, bus, conn, stream): @@ -21,18 +21,17 @@ def test(q, bus, conn, stream): ret, sig = q.expect_many( EventPattern('dbus-return', method='RequestChannel'), - EventPattern('dbus-signal', signal='NewChannel'), + EventPattern('dbus-signal', signal='NewChannels'), ) 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] == cs.CHANNEL_TYPE_TEXT, sig.args[1] + path, props = sig.args[0][0] + assertEquals(ret.value[0], path) + assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE]) # 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 + assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE]) + assertEquals(foo_handle, props[cs.TARGET_HANDLE]) # Exercise basic Channel Properties from spec 0.17.7 channel_props = text_chan.GetAll( diff --git a/tests/twisted/text/respawn.py b/tests/twisted/text/respawn.py index 9fba707..1d81084 100644 --- a/tests/twisted/text/respawn.py +++ b/tests/twisted/text/respawn.py @@ -19,9 +19,8 @@ def test(q, bus, conn, stream): call_async(q, conn, 'RequestChannel', cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, foo_handle, True) - ret, old_sig, new_sig = q.expect_many( + ret, new_sig = q.expect_many( EventPattern('dbus-return', method='RequestChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) @@ -29,12 +28,6 @@ def test(q, bus, conn, stream): chan_iface = dbus.Interface(text_chan, cs.CHANNEL) text_iface = dbus.Interface(text_chan, cs.CHANNEL_TYPE_TEXT) - assert old_sig.args[0] == ret.value[0] - assert old_sig.args[1] == cs.CHANNEL_TYPE_TEXT - assert old_sig.args[2] == cs.HT_CONTACT - 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 @@ -107,12 +100,12 @@ def test(q, bus, conn, stream): assert new.args[0] == text_chan.object_path,\ (new.args[0], text_chan.object_path) - event = q.expect('dbus-signal', signal='NewChannel') - assert event.args[0] == text_chan.object_path - assert event.args[1] == cs.CHANNEL_TYPE_TEXT - assert event.args[2] == cs.HT_CONTACT - assert event.args[3] == foo_handle - assert event.args[4] == False # suppress handler + event = q.expect('dbus-signal', signal='NewChannels') + path, props = event.args[0][0] + assertEquals(text_chan.object_path, path) + assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE]) + assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE]) + assertEquals(foo_handle, props[cs.TARGET_HANDLE]) event = q.expect('dbus-return', method='Close') diff --git a/tests/twisted/text/test-chat-state.py b/tests/twisted/text/test-chat-state.py index c39a940..6502fe3 100644 --- a/tests/twisted/text/test-chat-state.py +++ b/tests/twisted/text/test-chat-state.py @@ -168,10 +168,9 @@ def test(q, bus, conn, stream): # get a notification, and the channel should respawn. chan.Close() - gone, _, _ = q.expect_many( + gone, _ = q.expect_many( EventPattern('stream-message'), EventPattern('dbus-signal', signal='Closed'), - EventPattern('dbus-signal', signal='NewChannel'), ) check_state_notification(gone.stanza, 'gone') diff --git a/tests/twisted/text/test-text-delayed.py b/tests/twisted/text/test-text-delayed.py index b08f148..de1060f 100644 --- a/tests/twisted/text/test-text-delayed.py +++ b/tests/twisted/text/test-text-delayed.py @@ -8,7 +8,7 @@ import datetime from twisted.words.xish import domish from gabbletest import exec_test -from servicetest import EventPattern +from servicetest import EventPattern, assertEquals import constants as cs def test(q, bus, conn, stream): @@ -23,11 +23,12 @@ def test(q, bus, conn, stream): stream.send(m) - event = q.expect('dbus-signal', signal='NewChannel') - assert event.args[1] == cs.CHANNEL_TYPE_TEXT - assert event.args[2] == cs.HT_CONTACT - jid = conn.inspect_contact_sync(event.args[3]) - assert jid == 'foo@bar.com' + event = q.expect('dbus-signal', signal='NewChannels') + path, props = event.args[0][0] + assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE]) + assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE]) + jid = conn.inspect_contact_sync(props[cs.TARGET_HANDLE]) + assertEquals('foo@bar.com', jid) received, message_received = q.expect_many( EventPattern('dbus-signal', signal='Received'), diff --git a/tests/twisted/text/test-text.py b/tests/twisted/text/test-text.py index bb2e765..380d9a6 100644 --- a/tests/twisted/text/test-text.py +++ b/tests/twisted/text/test-text.py @@ -8,7 +8,8 @@ import dbus from twisted.words.xish import domish from gabbletest import exec_test, elem -from servicetest import (EventPattern, wrap_channel, assertEquals, assertLength) +from servicetest import (EventPattern, wrap_channel, assertEquals, assertLength, + assertContains) import constants as cs def test(q, bus, conn, stream): @@ -22,38 +23,27 @@ def test(q, bus, conn, stream): m.addElement('body', content='hello') stream.send(m) - event = q.expect('dbus-signal', signal='NewChannel') + event = q.expect('dbus-signal', signal='NewChannels') + path, props = event.args[0][0] text_chan = wrap_channel( - bus.get_object(conn.bus_name, event.args[0]), 'Text', ['Messages']) - assert event.args[1] == cs.CHANNEL_TYPE_TEXT - assert event.args[2] == cs.HT_CONTACT - foo_at_bar_dot_com_handle = event.args[3] + bus.get_object(conn.bus_name, path), 'Text', ['Messages']) + assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE]) + assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE]) + foo_at_bar_dot_com_handle = props[cs.TARGET_HANDLE] jid = conn.inspect_contact_sync(foo_at_bar_dot_com_handle) - assert jid == 'foo@bar.com' - assert event.args[4] == False # suppress handler + assertEquals('foo@bar.com', jid) # Exercise basic Channel Properties from spec 0.17.7 channel_props = text_chan.Properties.GetAll(cs.CHANNEL) - assert channel_props.get('TargetHandle') == event.args[3],\ - (channel_props.get('TargetHandle'), event.args[3]) - assert channel_props.get('TargetHandleType') == cs.HT_CONTACT,\ - channel_props.get('TargetHandleType') - assert channel_props.get('ChannelType') == \ - cs.CHANNEL_TYPE_TEXT,\ - channel_props.get('ChannelType') - assert cs.CHANNEL_IFACE_CHAT_STATE in \ - channel_props.get('Interfaces', ()), \ - channel_props.get('Interfaces') - assert cs.CHANNEL_IFACE_MESSAGES in \ - channel_props.get('Interfaces', ()), \ - channel_props.get('Interfaces') - assert channel_props['TargetID'] == jid,\ - (channel_props['TargetID'], jid) - assert channel_props['Requested'] == False - assert channel_props['InitiatorHandle'] == event.args[3],\ - (channel_props['InitiatorHandle'], event.args[3]) - assert channel_props['InitiatorID'] == jid,\ - (channel_props['InitiatorID'], jid) + assertEquals(props[cs.TARGET_HANDLE], channel_props.get('TargetHandle')) + assertEquals(cs.HT_CONTACT, channel_props.get('TargetHandleType')) + assertEquals(cs.CHANNEL_TYPE_TEXT, channel_props.get('ChannelType')) + assertContains(cs.CHANNEL_IFACE_CHAT_STATE, channel_props.get('Interfaces')) + assertContains(cs.CHANNEL_IFACE_MESSAGES, channel_props.get('Interfaces')) + assertEquals(jid, channel_props['TargetID']) + assertEquals(False, channel_props['Requested']) + assertEquals(props[cs.INITIATOR_HANDLE], channel_props['InitiatorHandle']) + assertEquals(jid, channel_props['InitiatorID']) received, message_received = q.expect_many( EventPattern('dbus-signal', signal='Received'), diff --git a/tests/twisted/tubes/accept-muc-stream-tube.py b/tests/twisted/tubes/accept-muc-stream-tube.py index 5c4f5cf..a209ab0 100644 --- a/tests/twisted/tubes/accept-muc-stream-tube.py +++ b/tests/twisted/tubes/accept-muc-stream-tube.py @@ -110,11 +110,7 @@ def test(q, bus, conn, stream, bytestream_cls, stream.send(presence) # text channel - event, new_event = q.expect_many( - EventPattern('dbus-signal', signal='NewChannel'), - EventPattern('dbus-signal', signal='NewChannels')) - - assert event.args[1] == cs.CHANNEL_TYPE_TEXT, event.args + new_event = q.expect('dbus-signal', signal='NewChannels') channels = new_event.args[0] assert len(channels) == 1 diff --git a/tests/twisted/tubes/check-create-tube-return.py b/tests/twisted/tubes/check-create-tube-return.py index 46db340..2f1e34a 100644 --- a/tests/twisted/tubes/check-create-tube-return.py +++ b/tests/twisted/tubes/check-create-tube-return.py @@ -39,9 +39,8 @@ def test(q, bus, conn, stream): stream.send(make_muc_presence('owner', 'moderator', muc, 'bob')) stream.send(make_muc_presence('none', 'participant', muc, 'test')) - ret, _, _ = q.expect_many( + ret, _ = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) @@ -62,9 +61,8 @@ def test(q, bus, conn, stream): cs.TARGET_ID: muc, cs.DBUS_TUBE_SERVICE_NAME: 'com.example.LolDongs'}) - ret, _, _ = q.expect_many( + ret, _ = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), - EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) -- 1.8.3.1