source: ralphm-patches/pubsub_client_sender.patch @ 4:c8c73d9e5496

Last change on this file since 4:c8c73d9e5496 was 4:c8c73d9e5496, checked in by Ralph Meijer <ralphm@…>, 12 years ago

Save bunch of work.

File size: 6.9 KB
  • wokkel/pubsub.py

    diff -r 8be0600d2c32 wokkel/pubsub.py
    a b  
    605605        pass
    606606
    607607
    608     def createNode(self, service, nodeIdentifier=None):
     608    def createNode(self, service, nodeIdentifier=None, sender=None):
    609609        """
    610610        Create a publish subscribe node.
    611611
     
    617617        request = PubSubRequest('create')
    618618        request.recipient = service
    619619        request.nodeIdentifier = nodeIdentifier
     620        request.sender = sender
    620621
    621622        def cb(iq):
    622623            try:
     
    631632        return d
    632633
    633634
    634     def deleteNode(self, service, nodeIdentifier):
     635    def deleteNode(self, service, nodeIdentifier, sender=None):
    635636        """
    636637        Delete a publish subscribe node.
    637638
     
    643644        request = PubSubRequest('delete')
    644645        request.recipient = service
    645646        request.nodeIdentifier = nodeIdentifier
     647        request.sender = sender
    646648        return request.send(self.xmlstream)
    647649
    648650
    649     def subscribe(self, service, nodeIdentifier, subscriber):
     651    def subscribe(self, service, nodeIdentifier, subscriber, sender=None):
    650652        """
    651653        Subscribe to a publish subscribe node.
    652654
     
    662664        request.recipient = service
    663665        request.nodeIdentifier = nodeIdentifier
    664666        request.subscriber = subscriber
     667        request.sender = sender
    665668
    666669        def cb(iq):
    667670            subscription = iq.pubsub.subscription["subscription"]
     
    681684        return d
    682685
    683686
    684     def unsubscribe(self, service, nodeIdentifier, subscriber):
     687    def unsubscribe(self, service, nodeIdentifier, subscriber, sender=None):
    685688        """
    686689        Unsubscribe from a publish subscribe node.
    687690
     
    696699        request.recipient = service
    697700        request.nodeIdentifier = nodeIdentifier
    698701        request.subscriber = subscriber
     702        request.sender = sender
    699703        return request.send(self.xmlstream)
    700704
    701705
    702     def publish(self, service, nodeIdentifier, items=None):
     706    def publish(self, service, nodeIdentifier, items=None, sender=None):
    703707        """
    704708        Publish to a publish subscribe node.
    705709
     
    714718        request.recipient = service
    715719        request.nodeIdentifier = nodeIdentifier
    716720        request.items = items
     721        request.sender = sender
    717722        return request.send(self.xmlstream)
    718723
    719724
    720     def items(self, service, nodeIdentifier, maxItems=None):
     725    def items(self, service, nodeIdentifier, maxItems=None, sender=None):
    721726        """
    722727        Retrieve previously published items from a publish subscribe node.
    723728
     
    733738        request.nodeIdentifier = nodeIdentifier
    734739        if maxItems:
    735740            request.maxItems = str(int(maxItems))
     741        request.sender = sender
    736742
    737743        def cb(iq):
    738744            items = []
  • wokkel/test/test_pubsub.py

    diff -r 8be0600d2c32 wokkel/test/test_pubsub.py
    a b  
    257257        return d
    258258
    259259
     260    def test_createNodeWithSender(self):
     261        """
     262        Test sending create request from a specific JID.
     263        """
     264
     265        d = self.protocol.createNode(JID('pubsub.example.org'), 'test',
     266                                     sender=JID('user@example.org'))
     267
     268        iq = self.stub.output[-1]
     269        self.assertEquals('user@example.org', iq['from'])
     270
     271        response = toResponse(iq, 'result')
     272        self.stub.send(response)
     273        return d
     274
     275
    260276    def test_deleteNode(self):
    261277        """
    262278        Test sending delete request.
     
    280296        return d
    281297
    282298
     299    def test_deleteNodeWithSender(self):
     300        """
     301        Test sending delete request.
     302        """
     303
     304        d = self.protocol.deleteNode(JID('pubsub.example.org'), 'test',
     305                                     sender=JID('user@example.org'))
     306
     307        iq = self.stub.output[-1]
     308        self.assertEquals('user@example.org', iq['from'])
     309
     310        response = toResponse(iq, 'result')
     311        self.stub.send(response)
     312        return d
     313
     314
    283315    def test_publish(self):
    284316        """
    285317        Test sending publish request.
     
    331363        return d
    332364
    333365
     366    def test_publishWithSender(self):
     367        """
     368        Test sending publish request from a specific JID.
     369        """
     370
     371        item = pubsub.Item()
     372        d = self.protocol.publish(JID('pubsub.example.org'), 'test', [item],
     373                                  JID('user@example.org'))
     374
     375        iq = self.stub.output[-1]
     376        self.assertEquals('user@example.org', iq['from'])
     377
     378        response = toResponse(iq, 'result')
     379        self.stub.send(response)
     380        return d
     381
     382
    334383    def test_subscribe(self):
    335384        """
    336385        Test sending subscription request.
     
    400449        return d
    401450
    402451
     452    def test_subscribeWithSender(self):
     453        """
     454        Test sending subscription request from a specific JID.
     455        """
     456        d = self.protocol.subscribe(JID('pubsub.example.org'), 'test',
     457                                      JID('user@example.org'),
     458                                      sender=JID('user@example.org'))
     459
     460        iq = self.stub.output[-1]
     461        self.assertEquals('user@example.org', iq['from'])
     462
     463        response = toResponse(iq, 'result')
     464        pubsub = response.addElement((NS_PUBSUB, 'pubsub'))
     465        subscription = pubsub.addElement('subscription')
     466        subscription['node'] = 'test'
     467        subscription['jid'] = 'user@example.org'
     468        subscription['subscription'] = 'subscribed'
     469        self.stub.send(response)
     470        return d
     471
     472
    403473    def test_unsubscribe(self):
    404474        """
    405475        Test sending unsubscription request.
     
    423493        return d
    424494
    425495
     496    def test_unsubscribeWithSender(self):
     497        """
     498        Test sending unsubscription request from a specific JID.
     499        """
     500        d = self.protocol.unsubscribe(JID('pubsub.example.org'), 'test',
     501                                      JID('user@example.org'),
     502                                      sender=JID('user@example.org'))
     503
     504        iq = self.stub.output[-1]
     505        self.assertEquals('user@example.org', iq['from'])
     506        self.stub.send(toResponse(iq, 'result'))
     507        return d
     508
     509
    426510    def test_items(self):
    427511        """
    428512        Test sending items request.
     
    489573        return d
    490574
    491575
     576    def test_itemsWithSender(self):
     577        """
     578        Test sending items request from a specific JID.
     579        """
     580
     581        d = self.protocol.items(JID('pubsub.example.org'), 'test',
     582                               sender=JID('user@example.org'))
     583
     584        iq = self.stub.output[-1]
     585        self.assertEquals('user@example.org', iq['from'])
     586
     587        response = toResponse(iq, 'result')
     588        items = response.addElement((NS_PUBSUB, 'pubsub')).addElement('items')
     589        items['node'] = 'test'
     590
     591        self.stub.send(response)
     592        return d
     593
     594
    492595
    493596class PubSubServiceTest(unittest.TestCase, TestableRequestHandlerMixin):
    494597    """
Note: See TracBrowser for help on using the repository browser.