Changeset 220:c8a97efc6fa6 for wokkel


Ignore:
Timestamp:
Aug 30, 2016, 9:41:31 PM (4 years ago)
Author:
souliane <souliane@…>
Branch:
default
committer:
souliane <souliane@mailoo.org> 1472587320 -7200
hg-git-rename-source:
git
Message:

implement item retrieval by IDs

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r166 r220  
    912912
    913913
    914     def items(self, service, nodeIdentifier, maxItems=None,
     914    def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None,
    915915              subscriptionIdentifier=None, sender=None):
    916916        """
     
    925925        @param maxItems: Optional limit on the number of retrieved items.
    926926        @type maxItems: C{int}
     927
     928        @param itemIdentifiers: Identifiers of the items to be retrieved.
     929        @type itemIdentifiers: C{set}
    927930
    928931        @param subscriptionIdentifier: Optional subscription identifier. In
     
    938941        request.subscriptionIdentifier = subscriptionIdentifier
    939942        request.sender = sender
     943        request.itemIdentifiers = itemIdentifiers
    940944
    941945        def cb(iq):
  • wokkel/test/test_pubsub.py

    r183 r220  
    802802
    803803
     804    def test_itemsWithItemIdentifiers(self):
     805        """
     806        Test sending items request with item identifiers.
     807        """
     808        def cb(items):
     809            self.assertEquals(2, len(items))
     810            self.assertEquals([item1, item2], items)
     811
     812        d = self.protocol.items(JID('pubsub.example.org'), 'test',
     813                                itemIdentifiers=['item1', 'item2'])
     814        d.addCallback(cb)
     815
     816        iq = self.stub.output[-1]
     817        self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
     818        self.assertEquals('get', iq.getAttribute('type'))
     819        self.assertEquals('pubsub', iq.pubsub.name)
     820        self.assertEquals(NS_PUBSUB, iq.pubsub.uri)
     821        children = list(domish.generateElementsQNamed(iq.pubsub.children,
     822                                                      'items', NS_PUBSUB))
     823        self.assertEquals(1, len(children))
     824        child = children[0]
     825        self.assertEquals('test', child['node'])
     826        itemIdentifiers = [item.getAttribute('id') for item in
     827                           domish.generateElementsQNamed(child.children, 'item',
     828                                                         NS_PUBSUB)]
     829        self.assertEquals(['item1', 'item2'], itemIdentifiers)
     830
     831        response = toResponse(iq, 'result')
     832        items = response.addElement((NS_PUBSUB, 'pubsub')).addElement('items')
     833        items['node'] = 'test'
     834        item1 = items.addElement('item')
     835        item1['id'] = 'item1'
     836        item2 = items.addElement('item')
     837        item2['id'] = 'item2'
     838
     839        self.stub.send(response)
     840
     841        return d
     842
     843
    804844    def test_itemsWithSubscriptionIdentifier(self):
    805845        """
Note: See TracChangeset for help on using the changeset viewer.