Ignore:
Timestamp:
May 9, 2012, 2:24:28 PM (8 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Add support for adding and updating roster items.

Roster items can be added or updated by sending a roster set request using the
new wokkel.xmppim.RosterClientProtocol.setItem. It takes a RosterItem as
the only argument. Note that changes in presence subscriptions for the contact
need to be done using presence as provided by
wokkel.xmppim.PresenceProtocol.

Author: ralphm.
Fixes: #56.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_xmppim.py

    r173 r174  
    966966
    967967
     968    def test_setItem(self):
     969        """
     970        Setting a roster item renders the item and sends it out.
     971        """
     972        item = xmppim.RosterItem(JID('test@example.org'),
     973                                 name='Joe User',
     974                                 groups=set(['Friends', 'Jabber']))
     975        d = self.service.setItem(item)
     976
     977        # Inspect outgoing iq request
     978
     979        iq = self.stub.output[-1]
     980        self.assertEqual('set', iq.getAttribute('type'))
     981        self.assertNotIdentical(None, iq.query)
     982        self.assertEqual(NS_ROSTER, iq.query.uri)
     983
     984        children = list(domish.generateElementsQNamed(iq.query.children,
     985                                                      'item', NS_ROSTER))
     986        self.assertEqual(1, len(children))
     987        child = children[0]
     988        self.assertEqual('test@example.org', child['jid'])
     989        self.assertIdentical(None, child.getAttribute('subscription'))
     990
     991        # Fake successful response
     992
     993        response = toResponse(iq, 'result')
     994        d.callback(response)
     995        return d
     996
     997
     998    def test_setItemIgnoreAttributes(self):
     999        """
     1000        Certain attributes should be rendered for roster set.
     1001        """
     1002        item = xmppim.RosterItem(JID('test@example.org'),
     1003                                 subscriptionTo=True,
     1004                                 subscriptionFrom=False,
     1005                                 name='Joe User',
     1006                                 groups=set(['Friends', 'Jabber']))
     1007        item.pendingOut = True
     1008        item.approved = True
     1009        d = self.service.setItem(item)
     1010
     1011        # Inspect outgoing iq request
     1012
     1013        iq = self.stub.output[-1]
     1014        self.assertEqual('set', iq.getAttribute('type'))
     1015        self.assertNotIdentical(None, iq.query)
     1016        self.assertEqual(NS_ROSTER, iq.query.uri)
     1017
     1018        children = list(domish.generateElementsQNamed(iq.query.children,
     1019                                                      'item', NS_ROSTER))
     1020        self.assertEqual(1, len(children))
     1021        child = children[0]
     1022        self.assertIdentical(None, child.getAttribute('ask'))
     1023        self.assertIdentical(None, child.getAttribute('approved'))
     1024        self.assertIdentical(None, child.getAttribute('subscription'))
     1025
     1026        # Fake successful response
     1027
     1028        response = toResponse(iq, 'result')
     1029        d.callback(response)
     1030        return d
     1031
     1032
    9681033    def test_removeItem(self):
    9691034        """
Note: See TracChangeset for help on using the changeset viewer.