Changeset 28:65fd5f2bd59e


Ignore:
Timestamp:
Jul 28, 2008, 5:07:40 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@58
Message:

Add client side support for removing a roster item.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_xmppim.py

    r9 r28  
    88from twisted.trial import unittest
    99from twisted.words.protocols.jabber.jid import JID
     10from twisted.words.protocols.jabber.xmlstream import toResponse
     11from twisted.words.xish import domish
     12
    1013from wokkel import xmppim
     14from wokkel.test.helpers import XmlStreamStub
     15
     16NS_ROSTER = 'jabber:iq:roster'
    1117
    1218class PresenceClientProtocolTest(unittest.TestCase):
     
    6874        self.assertEquals(None, presence.getAttribute('to'))
    6975        self.assertEquals("unavailable", presence.getAttribute('type'))
     76
     77
     78class RosterClientProtocolTest(unittest.TestCase):
     79    """
     80    Tests for L{xmppim.RosterClientProtocol}.
     81    """
     82
     83    def setUp(self):
     84        self.stub = XmlStreamStub()
     85        self.protocol = xmppim.RosterClientProtocol()
     86        self.protocol.xmlstream = self.stub.xmlstream
     87        self.protocol.connectionInitialized()
     88
     89
     90    def test_removeItem(self):
     91        """
     92        Removing a roster item is setting an item with subscription C{remove}.
     93        """
     94        d = self.protocol.removeItem(JID('test@example.org'))
     95
     96        # Inspect outgoing iq request
     97
     98        iq = self.stub.output[-1]
     99        self.assertEquals('set', iq.getAttribute('type'))
     100        self.assertNotIdentical(None, iq.query)
     101        self.assertEquals(NS_ROSTER, iq.query.uri)
     102
     103        children = list(domish.generateElementsQNamed(iq.query.children,
     104                                                      'item', NS_ROSTER))
     105        self.assertEquals(1, len(children))
     106        child = children[0]
     107        self.assertEquals('test@example.org', child['jid'])
     108        self.assertEquals('remove', child['subscription'])
     109
     110        # Fake successful response
     111
     112        response = toResponse(iq, 'result')
     113        self.stub.send(response)
     114        return d
  • wokkel/xmppim.py

    r12 r28  
    328328        return d
    329329
     330
     331    def removeItem(self, entity):
     332        """
     333        Remove an item from the contact list.
     334
     335        @param entity: The contact to remove the roster item for.
     336        @type entity: L{JID<twisted.words.protocols.jabber.jid.JID>}
     337        @rtype: L{twisted.internet.defer.Deferred}
     338        """
     339        iq = IQ(self.xmlstream, 'set')
     340        iq.addElement((NS_ROSTER, 'query'))
     341        item = iq.query.addElement('item')
     342        item['jid'] = entity.full()
     343        item['subscription'] = 'remove'
     344        return iq.send()
     345
     346
    330347    def _onRosterSet(self, iq):
    331348        if iq.handled or \
Note: See TracChangeset for help on using the changeset viewer.