From 27cfca065ceed41709842ee7c7e366d91b2fb141 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 23 Sep 2013 15:37:42 +0100 Subject: roster/subscribe.py: convert to ContactList, ContactGroups Bug: https://bugs.freedesktop.org/show_bug.cgi?id=49389 Reviewed-by: Guillaume Desmottes --- tests/twisted/roster/subscribe.py | 74 +++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/tests/twisted/roster/subscribe.py b/tests/twisted/roster/subscribe.py index 28f4107..b736d0d 100644 --- a/tests/twisted/roster/subscribe.py +++ b/tests/twisted/roster/subscribe.py @@ -15,50 +15,44 @@ import ns def test(q, bus, conn, stream): self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") - # Close all Group channels to get a clean slate, so we can rely on - # the NewChannels signal for the default group later - close_all_groups(q, bus, conn, stream) - - call_async(q, conn.Requests, 'EnsureChannel',{ - cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_CONTACT_LIST, - cs.TARGET_HANDLE_TYPE: cs.HT_LIST, - cs.TARGET_ID: 'subscribe', - }) - e = q.expect('dbus-return', method='EnsureChannel') - subscribe = wrap_channel(bus.get_object(conn.bus_name, e.value[1]), - cs.CHANNEL_TYPE_CONTACT_LIST) - jids = set(conn.inspect_contacts_sync(subscribe.Group.GetMembers())) - assertEquals(set(), jids) - - assertLength(0, subscribe.Group.GetMembers()) + call_async(q, conn.ContactList, 'GetContactListAttributes', + [cs.CONN_IFACE_CONTACT_GROUPS], False) + r = q.expect('dbus-return', method='GetContactListAttributes') + assertLength(0, r.value[0].keys()) # request subscription handle = conn.get_contact_handle_sync('suggs@night.boat.cairo') - call_async(q, subscribe.Group, 'AddMembers', [handle], '') + call_async(q, conn.ContactList, 'RequestSubscription', [handle], + 'half past monsoon') # libpurple puts him on our blist as soon as we've asked; there doesn't # seem to be any concept of remote-pending state. # # It also puts him in the default group, probably "Buddies". - set_iq, _, _, _, new_channels = q.expect_many( + set_iq, _, _, _, groups_changed = q.expect_many( EventPattern('stream-iq', iq_type='set', query_ns=ns.ROSTER, query_name='query'), EventPattern('stream-presence', presence_type='subscribe', to='suggs@night.boat.cairo'), - EventPattern('dbus-return', method='AddMembers', value=()), - # FIXME: TpBaseContactList wrongly assumes that he's the actor, - # because he must have accepted our request... right? Wrong. - EventPattern('dbus-signal', signal='MembersChanged', - path=subscribe.object_path, - args=['', [handle], [], [], [], handle, 0]), - EventPattern('dbus-signal', signal='NewChannels', - predicate=lambda e: - e.args[0][0][1].get(cs.TARGET_HANDLE_TYPE) == cs.HT_GROUP), + EventPattern('dbus-return', method='RequestSubscription', value=()), + EventPattern('dbus-signal', signal='ContactsChangedWithID', + args=[{ + handle: + (cs.SUBSCRIPTION_STATE_YES, + cs.SUBSCRIPTION_STATE_UNKNOWN, ''), + }, + {handle: 'suggs@night.boat.cairo'}, {}]), + EventPattern('dbus-signal', signal='GroupsChanged', + predicate=lambda e: e.args[0] == [handle]), ) assertEquals('suggs@night.boat.cairo', set_iq.query.item['jid']) acknowledge_iq(stream, set_iq.stanza) + assertLength(1, groups_changed.args[1]) + assertLength(0, groups_changed.args[2]) + def_group = groups_changed.args[1][0] + # Suggs accepts our subscription request presence = domish.Element(('jabber:client', 'presence')) presence['from'] = 'suggs@night.boat.cairo' @@ -68,15 +62,10 @@ def test(q, bus, conn, stream): # ... but nothing much happens, because there's no concept of pending # state in libpurple - def_group = wrap_channel(bus.get_object(conn.bus_name, - new_channels.args[0][0][0]), cs.CHANNEL_TYPE_CONTACT_LIST) - handles = set(subscribe.Group.GetMembers()) - assertEquals(set([handle]), handles) - # put a contact into the *group* explicitly: this shouldn't ask for - # subscription, but it does + # subscription, but it does, because libpurple handle = conn.get_contact_handle_sync('ayria@revenge.world') - call_async(q, def_group.Group, 'AddMembers', [handle], '') + call_async(q, conn.ContactGroups, 'AddToGroup', def_group, [handle]) # libpurple puts her on our blist as soon as we've asked; there doesn't # seem to be any concept of remote-pending state. It also puts her in the @@ -86,13 +75,16 @@ def test(q, bus, conn, stream): query_ns=ns.ROSTER, query_name='query'), EventPattern('stream-presence', presence_type='subscribe', to='ayria@revenge.world'), - EventPattern('dbus-return', method='AddMembers', value=()), - EventPattern('dbus-signal', signal='MembersChanged', - path=subscribe.object_path, - args=['', [handle], [], [], [], handle, 0]), - EventPattern('dbus-signal', signal='MembersChanged', - path=def_group.object_path, - args=['', [handle], [], [], [], self_handle, 0]), + EventPattern('dbus-return', method='AddToGroup', value=()), + EventPattern('dbus-signal', signal='ContactsChangedWithID', + args=[{ + handle: + (cs.SUBSCRIPTION_STATE_YES, + cs.SUBSCRIPTION_STATE_UNKNOWN, ''), + }, + {handle: 'ayria@revenge.world'}, {}]), + EventPattern('dbus-signal', signal='GroupsChanged', + args=[[handle], [def_group], []]), ) acknowledge_iq(stream, set_iq.stanza) -- cgit v1.2.1