source: ralphm-patches/pubsub_client_sender.patch @ 5:231bc3e8b810

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

A gazillion changes.

File size: 6.9 KB
  • wokkel/pubsub.py

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