Changeset 17:d42fd6c92576


Ignore:
Timestamp:
Apr 15, 2008, 7:32:14 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@47
Message:

Add client support for getting items from a node.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r15 r17  
    231231        return item
    232232
     233class Items(PubSubRequest):
     234    verb = 'items'
     235    method = 'get'
     236
     237    def __init__(self, xs, node):
     238        PubSubRequest.__init__(self, xs)
     239        self.command["node"] = node
    233240
    234241class PubSubClient(XMPPHandler):
     
    334341        return request.send(service)
    335342
     343    def items(self, service, nodeIdentifier):
     344        def cb(iq):
     345            items = []
     346            for element in iq.pubsub.items.elements():
     347                if element.uri == NS_PUBSUB and element.name == 'item':
     348                    items.append(element)
     349            return items
     350
     351        request = Items(self.xmlstream, nodeIdentifier)
     352        return request.send(service).addCallback(cb)
    336353
    337354class PubSubService(XMPPHandler, IQHandlerMixin):
  • wokkel/test/test_pubsub.py

    r13 r17  
    140140        return d
    141141
     142
     143    def test_items(self):
     144        """
     145        Test sending items request.
     146        """
     147        def cb(items):
     148            self.assertEquals([], items)
     149
     150        d = self.protocol.items(JID('pubsub.example.org'), 'test')
     151        d.addCallback(cb)
     152
     153        iq = self.stub.output[-1]
     154        self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
     155        self.assertEquals('get', iq.getAttribute('type'))
     156        self.assertEquals('pubsub', iq.pubsub.name)
     157        self.assertEquals(NS_PUBSUB, iq.pubsub.uri)
     158        children = list(domish.generateElementsQNamed(iq.pubsub.children,
     159                                                      'items', NS_PUBSUB))
     160        self.assertEquals(1, len(children))
     161        child = children[0]
     162        self.assertEquals('test', child['node'])
     163
     164        response = toResponse(iq, 'result')
     165        items = response.addElement((NS_PUBSUB, 'pubsub')).addElement('items')
     166        items['node'] = 'test'
     167
     168        self.stub.send(response)
     169
     170        return d
     171
    142172class PubSubServiceTest(unittest.TestCase):
    143173
Note: See TracChangeset for help on using the changeset viewer.