From 5c395b47ac277179fafb153340656598c7348bf8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 30 Nov 2010 17:42:57 +0000 Subject: Add close_all_groups() and use it to get rid of any stray groups The group tests are sensitive to leftover groups that might exist in global libpurple state. --- tests/twisted/hazetest.py | 10 ++++++++++ tests/twisted/roster/groups.py | 6 +++++- tests/twisted/roster/publish.py | 6 +++++- tests/twisted/roster/subscribe.py | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/twisted/hazetest.py b/tests/twisted/hazetest.py index c179309..2c43b53 100644 --- a/tests/twisted/hazetest.py +++ b/tests/twisted/hazetest.py @@ -792,3 +792,13 @@ def make_presence(_from, to='test@localhost', type=None, show=None, x.addElement('photo').addContent(photo) return presence + +def close_all_groups(q, bus, conn, stream): + channels = conn.Properties.Get(cs.CONN_IFACE_REQUESTS, 'Channels') + for path, props in channels: + if props.get(cs.CHANNEL_TYPE) != cs.CHANNEL_TYPE_CONTACT_LIST: + continue + if props.get(cs.TARGET_HANDLE_TYPE) != cs.HT_GROUP: + continue + wrap_channel(bus.get_object(conn.bus_name, path), + cs.CHANNEL_TYPE_CONTACT_LIST).Close() diff --git a/tests/twisted/roster/groups.py b/tests/twisted/roster/groups.py index 0e5e137..9d7dff6 100644 --- a/tests/twisted/roster/groups.py +++ b/tests/twisted/roster/groups.py @@ -9,7 +9,7 @@ from twisted.words.xish import domish, xpath from servicetest import (EventPattern, wrap_channel, assertLength, assertEquals, call_async, sync_dbus, assertContains) -from hazetest import acknowledge_iq, exec_test, sync_stream +from hazetest import acknowledge_iq, exec_test, sync_stream, close_all_groups import constants as cs import ns @@ -18,6 +18,10 @@ def test(q, bus, conn, stream): q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) + # 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, diff --git a/tests/twisted/roster/publish.py b/tests/twisted/roster/publish.py index b78425e..45bdcd3 100644 --- a/tests/twisted/roster/publish.py +++ b/tests/twisted/roster/publish.py @@ -9,7 +9,7 @@ from twisted.words.xish import domish from servicetest import (EventPattern, wrap_channel, assertLength, assertEquals, call_async, sync_dbus) -from hazetest import acknowledge_iq, exec_test, sync_stream +from hazetest import acknowledge_iq, exec_test, sync_stream, close_all_groups import constants as cs import ns @@ -18,6 +18,10 @@ def test(q, bus, conn, stream): q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) + # 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, diff --git a/tests/twisted/roster/subscribe.py b/tests/twisted/roster/subscribe.py index 8c718c4..66c5a8c 100644 --- a/tests/twisted/roster/subscribe.py +++ b/tests/twisted/roster/subscribe.py @@ -8,7 +8,7 @@ from twisted.words.xish import domish from servicetest import (EventPattern, wrap_channel, assertLength, assertEquals, call_async, sync_dbus) -from hazetest import acknowledge_iq, exec_test, sync_stream +from hazetest import acknowledge_iq, exec_test, sync_stream, close_all_groups import constants as cs import ns @@ -17,6 +17,10 @@ def test(q, bus, conn, stream): q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) + # 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, -- cgit v1.2.1