From 0be572308fa0e86c843e6333d853e88e26a82bd9 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 13 Feb 2012 11:51:11 +0100 Subject: [PATCH] groups.py: factor out send_roster_push() https://bugs.freedesktop.org/show_bug.cgi?id=45982 --- tests/twisted/roster/groups.py | 36 +++++++++++++----------------------- 1 files changed, 13 insertions(+), 23 deletions(-) diff --git a/tests/twisted/roster/groups.py b/tests/twisted/roster/groups.py index 7126639..e40410c 100644 --- a/tests/twisted/roster/groups.py +++ b/tests/twisted/roster/groups.py @@ -22,6 +22,16 @@ def parse_roster_change_request(query, iq): return item['jid'], groups +def send_roster_push(stream, jid, groups): + iq = IQ(stream, 'set') + query = iq.addElement((ns.ROSTER, 'query')) + item = query.addElement('item') + item['jid'] = jid + item['subscription'] = 'both' + for group in groups: + item.addElement('group', content=group) + stream.send(iq) + def test(q, bus, conn, stream): event = q.expect('stream-iq', query_ns=ns.ROSTER) event.stanza['type'] = 'result' @@ -92,14 +102,7 @@ def test(q, bus, conn, stream): q.expect('dbus-return', method='SetContactGroups') # Now the server sends us a roster push. - iq = IQ(stream, 'set') - query = iq.addElement((ns.ROSTER, 'query')) - item = query.addElement('item') - item['jid'] = 'amy@foo.com' - item['subscription'] = 'both' - item.addElement('group', content='people starting with A') - item.addElement('group', content='ladies') - stream.send(iq) + send_roster_push(stream, 'amy@foo.com', ['people starting with A', 'ladies']) # We get a single signal corresponding to that roster push e = q.expect('dbus-signal', signal='GroupsChanged', @@ -144,23 +147,10 @@ def test(q, bus, conn, stream): if it_worked: # ... although in fact this is what *actually* removes Amy from the # group - iq = IQ(stream, 'set') - query = iq.addElement((ns.ROSTER, 'query')) - item = query.addElement('item') - item['jid'] = 'amy@foo.com' - item['subscription'] = 'both' - item.addElement('group', content='ladies') - stream.send(iq) + send_roster_push(stream, 'amy@foo.com', ['ladies']) else: # if the change didn't "stick", this message will revert it - iq = IQ(stream, 'set') - query = iq.addElement((ns.ROSTER, 'query')) - item = query.addElement('item') - item['jid'] = 'amy@foo.com' - item['subscription'] = 'both' - item.addElement('group', content='ladies') - item.addElement('group', content='people starting with A') - stream.send(iq) + send_roster_push(stream, 'amy@foo.com', ['ladies', 'people starting with A']) q.expect('dbus-signal', signal='GroupsCreated', args=[['people starting with A']]) -- 1.7.7.6