From 965a41bc8a8316ba86bbd49b13f272f5939f1529 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 20 Sep 2013 17:17:24 +0100 Subject: [PATCH 08/10] MUC tests: modernize a bit We're better off using MembersChangedDetailed, which maps 1:1 into MembersChanged in Telepathy 1.0. Telepathy 1.0 no longer has RequestHandles, so cut out the middle-man and request MUC channels by TargetID. Hard-coding that the first two contacts we see are handles 2 and 3 is just horrible - let's not do that. --- tests/twisted/muc/test-muc-alias.py | 35 ++++++++++----- tests/twisted/tubes/accept-muc-stream-tube.py | 45 +++++++++++--------- tests/twisted/tubes/close-muc-with-closed-tube.py | 52 ++++++++++++++--------- tests/twisted/tubes/test-get-available-tubes.py | 14 ++++-- 4 files changed, 93 insertions(+), 53 deletions(-) diff --git a/tests/twisted/muc/test-muc-alias.py b/tests/twisted/muc/test-muc-alias.py index 60c837f..ab430bc 100644 --- a/tests/twisted/muc/test-muc-alias.py +++ b/tests/twisted/muc/test-muc-alias.py @@ -20,15 +20,24 @@ def test(q, bus, conn, stream): args=[[(self_handle, u'lala')]]) room_jid = 'chat@conf.localhost' - room_handle = request_muc_handle(q, conn, stream, room_jid) - call_async(q, conn, 'RequestChannel', cs.CHANNEL_TYPE_TEXT, cs.HT_ROOM, - room_handle, True) + # muc stream tube + call_async(q, conn.Requests, 'CreateChannel', { + cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, + cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, + cs.TARGET_ID: room_jid}) gfc, _, _ = q.expect_many( EventPattern('dbus-signal', signal='GroupFlagsChanged'), - EventPattern('dbus-signal', signal='MembersChanged', - args=[u'', [], [], [], [2], 0, 0]), + EventPattern('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + e.args[0] == [] and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + len(e.args[3]) == 1 and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + e.args[4]['contact-ids'][e.args[3][0]] == 'chat@conf.localhost/lala'), EventPattern('stream-presence', to='%s/lala' % room_jid)) assert gfc.args[1] == 0 @@ -38,12 +47,18 @@ def test(q, bus, conn, stream): # Send presence for own membership of room. stream.send(make_muc_presence('none', 'participant', room_jid, 'lala')) - event = q.expect('dbus-signal', signal='MembersChanged', - args=[u'', [2, 3], [], [], [], 0, 0]) - assert conn.InspectHandles(1, [2]) == ['chat@conf.localhost/lala'] - assert conn.InspectHandles(1, [3]) == ['chat@conf.localhost/bob'] + event = q.expect('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + len(e.args[0]) == 2 and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + e.args[3] == [] and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + set([e.args[4]['contact-ids'][h] for h in e.args[0]]) == + set(['chat@conf.localhost/lala', 'chat@conf.localhost/bob'])) - event = q.expect('dbus-return', method='RequestChannel') + event = q.expect('dbus-return', method='CreateChannel') if __name__ == '__main__': exec_test(test) diff --git a/tests/twisted/tubes/accept-muc-stream-tube.py b/tests/twisted/tubes/accept-muc-stream-tube.py index 7fc4aa0..5c4f5cf 100644 --- a/tests/twisted/tubes/accept-muc-stream-tube.py +++ b/tests/twisted/tubes/accept-muc-stream-tube.py @@ -40,22 +40,22 @@ def test(q, bus, conn, stream, bytestream_cls, announce_socks5_proxy(q, stream, disco_event.stanza) - call_async(q, conn, 'RequestHandles', 2, - ['chat@conf.localhost']) - - event = q.expect('dbus-return', method='RequestHandles') - handles = event.value[0] - room_handle = handles[0] - # join the muc call_async(q, conn.Requests, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, - cs.TARGET_HANDLE: room_handle}) - - _, stream_event = q.expect_many( - EventPattern('dbus-signal', signal='MembersChanged', - args=[u'', [], [], [], [2], 0, 0]), + cs.TARGET_ID: 'chat@conf.localhost'}) + + q.expect_many( + EventPattern('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + e.args[0] == [] and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + len(e.args[3]) == 1 and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + e.args[4]['contact-ids'][e.args[3][0]] == 'chat@conf.localhost/test'), EventPattern('stream-presence', to='chat@conf.localhost/test')) # Send presence for other member of room. @@ -64,12 +64,20 @@ def test(q, bus, conn, stream, bytestream_cls, # Send presence for own membership of room. stream.send(make_muc_presence('none', 'participant', 'chat@conf.localhost', 'test')) - q.expect('dbus-signal', signal='MembersChanged', - args=[u'', [2, 3], [], [], [], 0, 0]) - - assert conn.InspectHandles(1, [2]) == ['chat@conf.localhost/test'] - assert conn.InspectHandles(1, [3]) == ['chat@conf.localhost/bob'] - bob_handle = 3 + event = q.expect('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + len(e.args[0]) == 2 and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + e.args[3] == [] and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + set([e.args[4]['contact-ids'][h] for h in e.args[0]]) == + set(['chat@conf.localhost/test', 'chat@conf.localhost/bob'])) + + for h in event.args[0]: + if event.args[4]['contact-ids'][h] == 'chat@conf.localhost/bob': + bob_handle = h event = q.expect('dbus-return', method='CreateChannel') @@ -130,7 +138,6 @@ def test(q, bus, conn, stream, bytestream_cls, assertSameSets([cs.CHANNEL_IFACE_GROUP, cs.CHANNEL_IFACE_TUBE], props[cs.INTERFACES]) assert props[cs.REQUESTED] == False - assert props[cs.TARGET_HANDLE] == room_handle assert props[cs.TARGET_ID] == 'chat@conf.localhost' assert props[cs.STREAM_TUBE_SERVICE] == 'echo' assert props[cs.TUBE_PARAMETERS] == {'s': 'hello', 'ay': 'hello', 'u': 123, 'i': -123} diff --git a/tests/twisted/tubes/close-muc-with-closed-tube.py b/tests/twisted/tubes/close-muc-with-closed-tube.py index ed08add..c5a7a5d 100644 --- a/tests/twisted/tubes/close-muc-with-closed-tube.py +++ b/tests/twisted/tubes/close-muc-with-closed-tube.py @@ -21,19 +21,22 @@ def test(q, bus, conn, stream): acknowledge_iq(stream, iq_event.stanza) - call_async(q, conn, 'RequestHandles', cs.HT_ROOM, ['chat@conf.localhost']) - - event = q.expect('dbus-return', method='RequestHandles') - handles = event.value[0] - room_handle = handles[0] - # join the muc - call_async(q, conn, 'RequestChannel', - cs.CHANNEL_TYPE_TEXT, cs.HT_ROOM, room_handle, True) - - _, stream_event = q.expect_many( - EventPattern('dbus-signal', signal='MembersChanged', - args=[u'', [], [], [], [2], 0, 0]), + call_async(q, conn.Requests, 'CreateChannel', { + cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, + cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, + cs.TARGET_ID: 'chat@conf.localhost'}) + + q.expect_many( + EventPattern('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + e.args[0] == [] and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + len(e.args[3]) == 1 and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + e.args[4]['contact-ids'][e.args[3][0]] == 'chat@conf.localhost/test'), EventPattern('stream-presence', to='chat@conf.localhost/test')) # Send presence for other member of room. @@ -42,14 +45,22 @@ def test(q, bus, conn, stream): # Send presence for own membership of room. stream.send(make_muc_presence('none', 'participant', 'chat@conf.localhost', 'test')) - q.expect('dbus-signal', signal='MembersChanged', - args=[u'', [2, 3], [], [], [], 0, 0]) - - assert conn.InspectHandles(cs.HT_CONTACT, [2, 3]) == \ - ['chat@conf.localhost/test', 'chat@conf.localhost/bob'] - bob_handle = 3 - - event = q.expect('dbus-return', method='RequestChannel') + event = q.expect('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + len(e.args[0]) == 2 and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + e.args[3] == [] and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + set([e.args[4]['contact-ids'][h] for h in e.args[0]]) == + set(['chat@conf.localhost/test', 'chat@conf.localhost/bob'])) + + for h in event.args[0]: + if event.args[4]['contact-ids'][h] == 'chat@conf.localhost/bob': + bob_handle = h + + event = q.expect('dbus-return', method='CreateChannel') text_chan = bus.get_object(conn.bus_name, event.value[0]) # Bob offers a muc tube @@ -96,7 +107,6 @@ def test(q, bus, conn, stream): assertEquals(cs.CHANNEL_TYPE_DBUS_TUBE, props[cs.CHANNEL_TYPE]) assertEquals(cs.HT_ROOM, props[cs.TARGET_HANDLE_TYPE]) - assertEquals(room_handle, props[cs.TARGET_HANDLE]) assertEquals('chat@conf.localhost', props[cs.TARGET_ID]) assertEquals(False, props[cs.REQUESTED]) diff --git a/tests/twisted/tubes/test-get-available-tubes.py b/tests/twisted/tubes/test-get-available-tubes.py index 7b860eb..a550848 100644 --- a/tests/twisted/tubes/test-get-available-tubes.py +++ b/tests/twisted/tubes/test-get-available-tubes.py @@ -39,9 +39,17 @@ def test(q, bus, conn, stream): # Send presence for own membership of room. stream.send(make_muc_presence('owner', 'moderator', 'chat@conf.localhost', 'test')) - members, event = q.expect_many( - EventPattern('dbus-signal', signal='MembersChanged', - args=[u'', [2, 3], [], [], [], 0, 0]), + _, event = q.expect_many( + EventPattern('dbus-signal', signal='MembersChangedDetailed', + predicate=lambda e: + len(e.args[0]) == 2 and # added + e.args[1] == [] and # removed + e.args[2] == [] and # local pending + e.args[3] == [] and # remote pending + e.args[4].get('actor', 0) == 0 and + e.args[4].get('change-reason', 0) == 0 and + set([e.args[4]['contact-ids'][h] for h in e.args[0]]) == + set(['chat@conf.localhost/test', 'chat@conf.localhost/bob'])), EventPattern('dbus-return', method='CreateChannel')) path = event.value[0] -- 1.8.4.rc3