Changeset 58:a8c2aadabebd


Ignore:
Timestamp:
Apr 22, 2009, 5:02:49 PM (12 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@170
Message:

Allow publish-subscribe client requests to come from a specific JID.

Author: ralphm.
Fixes #46.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r57 r58  
    625625
    626626
    627     def createNode(self, service, nodeIdentifier=None):
     627    def createNode(self, service, nodeIdentifier=None, sender=None):
    628628        """
    629629        Create a publish subscribe node.
     
    637637        request.recipient = service
    638638        request.nodeIdentifier = nodeIdentifier
     639        request.sender = sender
    639640
    640641        def cb(iq):
     
    651652
    652653
    653     def deleteNode(self, service, nodeIdentifier):
     654    def deleteNode(self, service, nodeIdentifier, sender=None):
    654655        """
    655656        Delete a publish subscribe node.
     
    663664        request.recipient = service
    664665        request.nodeIdentifier = nodeIdentifier
     666        request.sender = sender
    665667        return request.send(self.xmlstream)
    666668
    667669
    668     def subscribe(self, service, nodeIdentifier, subscriber):
     670    def subscribe(self, service, nodeIdentifier, subscriber, sender=None):
    669671        """
    670672        Subscribe to a publish subscribe node.
     
    682684        request.nodeIdentifier = nodeIdentifier
    683685        request.subscriber = subscriber
     686        request.sender = sender
    684687
    685688        def cb(iq):
     
    701704
    702705
    703     def unsubscribe(self, service, nodeIdentifier, subscriber):
     706    def unsubscribe(self, service, nodeIdentifier, subscriber, sender=None):
    704707        """
    705708        Unsubscribe from a publish subscribe node.
     
    716719        request.nodeIdentifier = nodeIdentifier
    717720        request.subscriber = subscriber
     721        request.sender = sender
    718722        return request.send(self.xmlstream)
    719723
    720724
    721     def publish(self, service, nodeIdentifier, items=None):
     725    def publish(self, service, nodeIdentifier, items=None, sender=None):
    722726        """
    723727        Publish to a publish subscribe node.
     
    734738        request.nodeIdentifier = nodeIdentifier
    735739        request.items = items
     740        request.sender = sender
    736741        return request.send(self.xmlstream)
    737742
    738743
    739     def items(self, service, nodeIdentifier, maxItems=None):
     744    def items(self, service, nodeIdentifier, maxItems=None, sender=None):
    740745        """
    741746        Retrieve previously published items from a publish subscribe node.
     
    753758        if maxItems:
    754759            request.maxItems = str(int(maxItems))
     760        request.sender = sender
    755761
    756762        def cb(iq):
  • wokkel/test/test_pubsub.py

    r57 r58  
    256256
    257257
     258    def test_createNodeWithSender(self):
     259        """
     260        Test sending create request from a specific JID.
     261        """
     262
     263        d = self.protocol.createNode(JID('pubsub.example.org'), 'test',
     264                                     sender=JID('user@example.org'))
     265
     266        iq = self.stub.output[-1]
     267        self.assertEquals('user@example.org', iq['from'])
     268
     269        response = toResponse(iq, 'result')
     270        self.stub.send(response)
     271        return d
     272
     273
    258274    def test_deleteNode(self):
    259275        """
     
    273289        child = children[0]
    274290        self.assertEquals('test', child['node'])
     291
     292        response = toResponse(iq, 'result')
     293        self.stub.send(response)
     294        return d
     295
     296
     297    def test_deleteNodeWithSender(self):
     298        """
     299        Test sending delete request.
     300        """
     301
     302        d = self.protocol.deleteNode(JID('pubsub.example.org'), 'test',
     303                                     sender=JID('user@example.org'))
     304
     305        iq = self.stub.output[-1]
     306        self.assertEquals('user@example.org', iq['from'])
    275307
    276308        response = toResponse(iq, 'result')
     
    330362
    331363
     364    def test_publishWithSender(self):
     365        """
     366        Test sending publish request from a specific JID.
     367        """
     368
     369        item = pubsub.Item()
     370        d = self.protocol.publish(JID('pubsub.example.org'), 'test', [item],
     371                                  JID('user@example.org'))
     372
     373        iq = self.stub.output[-1]
     374        self.assertEquals('user@example.org', iq['from'])
     375
     376        response = toResponse(iq, 'result')
     377        self.stub.send(response)
     378        return d
     379
     380
    332381    def test_subscribe(self):
    333382        """
     
    399448
    400449
     450    def test_subscribeWithSender(self):
     451        """
     452        Test sending subscription request from a specific JID.
     453        """
     454        d = self.protocol.subscribe(JID('pubsub.example.org'), 'test',
     455                                      JID('user@example.org'),
     456                                      sender=JID('user@example.org'))
     457
     458        iq = self.stub.output[-1]
     459        self.assertEquals('user@example.org', iq['from'])
     460
     461        response = toResponse(iq, 'result')
     462        pubsub = response.addElement((NS_PUBSUB, 'pubsub'))
     463        subscription = pubsub.addElement('subscription')
     464        subscription['node'] = 'test'
     465        subscription['jid'] = 'user@example.org'
     466        subscription['subscription'] = 'subscribed'
     467        self.stub.send(response)
     468        return d
     469
     470
    401471    def test_unsubscribe(self):
    402472        """
     
    422492
    423493
     494    def test_unsubscribeWithSender(self):
     495        """
     496        Test sending unsubscription request from a specific JID.
     497        """
     498        d = self.protocol.unsubscribe(JID('pubsub.example.org'), 'test',
     499                                      JID('user@example.org'),
     500                                      sender=JID('user@example.org'))
     501
     502        iq = self.stub.output[-1]
     503        self.assertEquals('user@example.org', iq['from'])
     504        self.stub.send(toResponse(iq, 'result'))
     505        return d
     506
     507
    424508    def test_items(self):
    425509        """
     
    485569        self.stub.send(response)
    486570
     571        return d
     572
     573
     574    def test_itemsWithSender(self):
     575        """
     576        Test sending items request from a specific JID.
     577        """
     578
     579        d = self.protocol.items(JID('pubsub.example.org'), 'test',
     580                               sender=JID('user@example.org'))
     581
     582        iq = self.stub.output[-1]
     583        self.assertEquals('user@example.org', iq['from'])
     584
     585        response = toResponse(iq, 'result')
     586        items = response.addElement((NS_PUBSUB, 'pubsub')).addElement('items')
     587        items['node'] = 'test'
     588
     589        self.stub.send(response)
    487590        return d
    488591
Note: See TracChangeset for help on using the changeset viewer.