Changeset 43:0a525d09169d


Ignore:
Timestamp:
Oct 27, 2008, 2:21:23 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@127
Message:

Add support for sending and receiving node delete notifications with redirect.

Location:
wokkel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wokkel/iwokkel.py

    r31 r43  
    270270        """
    271271
    272     def notifyDelete(service, nodeIdentifier, subscriptions):
     272    def notifyDelete(service, nodeIdentifier, subscribers,
     273                     redirectURI=None):
    273274        """
    274275        Send out node deletion notifications.
     
    278279        @param nodeIdentifier: The identifier of the node that was deleted.
    279280        @type nodeIdentifier: C{unicode}
    280         @param subscriptions: The subscriptions for which a notification should
    281                               be sent out.
    282         @type subscriptions: C{list} of L{jid.JID}
     281        @param subscribers: The subscribers for which a notification should
     282                            be sent out.
     283        @type subscribers: C{list} of L{jid.JID}
     284        @param redirectURI: Optional XMPP URI of another node that subscribers
     285                            are redirected to.
     286        @type redirectURI: C{str}
    283287        """
    284288
     
    414418        """
    415419
    416     def getDefaultConfiguration(requestor, service):
     420    def getDefaultConfiguration(requestor, service, nodeType):
    417421        """
    418422        Called when a default node configuration request has been received.
     
    422426        @param service: The entity the request was addressed to.
    423427        @type service: L{jid.JID}
     428        @param nodeType: The type of node for which the configuration is
     429                         retrieved, C{'leaf'} or C{'collection'}.
     430        @type nodeType: C{str}
    424431        @return: A deferred that fires with a C{dict} representing the default
    425432                 node configuration. Keys are C{str}s that represent the
  • wokkel/pubsub.py

    r33 r43  
    246246    """
    247247
     248    redirectURI = None
     249
    248250
    249251
     
    303305        nodeIdentifier = action["node"]
    304306        event = DeleteEvent(sender, recipient, nodeIdentifier, headers)
     307        if action.redirect:
     308            event.redirectURI = action.redirect.getAttribute('uri')
    305309        self.deleteReceived(event)
    306310
     
    966970
    967971
    968     def notifyDelete(self, service, nodeIdentifier, subscriptions):
    969         for subscription in subscriptions:
     972    def notifyDelete(self, service, nodeIdentifier, subscribers,
     973                           redirectURI=None):
     974        for subscriber in subscribers:
    970975            message = self._createNotification('delete', service,
    971976                                               nodeIdentifier,
    972                                                subscription.subscriber)
     977                                               subscriber)
     978            if redirectURI:
     979                redirect = message.event.delete.addElement('redirect')
     980                redirect['uri'] = redirectURI
    973981            self.send(message)
    974982
     
    10101018
    10111019
    1012     def getDefaultConfiguration(self, requestor, service):
     1020    def getDefaultConfiguration(self, requestor, service, nodeType):
    10131021        raise Unsupported('retrieve-default')
    10141022
  • wokkel/test/test_pubsub.py

    r33 r43  
    116116
    117117
    118     def test_event_delete(self):
     118    def test_eventDelete(self):
    119119        """
    120120        Test receiving a delete event resulting in a call to deleteReceived.
     
    124124        message['to'] = 'user@example.org/home'
    125125        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
    126         items = event.addElement('delete')
    127         items['node'] = 'test'
     126        delete = event.addElement('delete')
     127        delete['node'] = 'test'
    128128
    129129        def deleteReceived(event):
     
    131131            self.assertEquals(JID('pubsub.example.org'), event.sender)
    132132            self.assertEquals('test', event.nodeIdentifier)
     133
     134        d, self.protocol.deleteReceived = calledAsync(deleteReceived)
     135        self.stub.send(message)
     136        return d
     137
     138
     139    def test_eventDeleteRedirect(self):
     140        """
     141        Test receiving a delete event with a redirect URI.
     142        """
     143        message = domish.Element((None, 'message'))
     144        message['from'] = 'pubsub.example.org'
     145        message['to'] = 'user@example.org/home'
     146        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
     147        delete = event.addElement('delete')
     148        delete['node'] = 'test'
     149        uri = 'xmpp:pubsub.example.org?;node=test2'
     150        delete.addElement('redirect')['uri'] = uri
     151
     152        def deleteReceived(event):
     153            self.assertEquals(JID('user@example.org/home'), event.recipient)
     154            self.assertEquals(JID('pubsub.example.org'), event.sender)
     155            self.assertEquals('test', event.nodeIdentifier)
     156            self.assertEquals(uri, event.redirectURI)
    133157
    134158        d, self.protocol.deleteReceived = calledAsync(deleteReceived)
     
    474498
    475499    def setUp(self):
     500        self.stub = XmlStreamStub()
    476501        self.service = pubsub.PubSubService()
     502        self.service.send = self.stub.xmlstream.send
    477503
    478504    def handleRequest(self, xml):
     
    657683        self.service.getConfigurationOptions = getConfigurationOptions
    658684        self.service.getDefaultConfiguration = getDefaultConfiguration
     685        verify.verifyObject(iwokkel.IPubSubService, self.service)
    659686        d = self.handleRequest(xml)
    660687        d.addCallback(cb)
     
    948975        self.service.delete = delete
    949976        return self.handleRequest(xml)
     977
     978
     979    def test_notifyDelete(self):
     980        """
     981        Subscribers should be sent a delete notification.
     982        """
     983        subscriptions = [JID('user@example.org')]
     984        self.service.notifyDelete(JID('pubsub.example.org'), 'test',
     985                                  subscriptions)
     986        message = self.stub.output[-1]
     987
     988        self.assertEquals('message', message.name)
     989        self.assertIdentical(None, message.uri)
     990        self.assertEquals('user@example.org', message['to'])
     991        self.assertEquals('pubsub.example.org', message['from'])
     992        self.assertTrue(message.event)
     993        self.assertEqual(NS_PUBSUB_EVENT, message.event.uri)
     994        self.assertTrue(message.event.delete)
     995        self.assertEqual(NS_PUBSUB_EVENT, message.event.delete.uri)
     996        self.assertTrue(message.event.delete.hasAttribute('node'))
     997        self.assertEqual('test', message.event.delete['node'])
     998
     999
     1000    def test_notifyDeleteRedirect(self):
     1001        """
     1002        Subscribers should be sent a delete notification with redirect.
     1003        """
     1004        redirectURI = 'xmpp:pubsub.example.org?;node=test2'
     1005        subscriptions = [JID('user@example.org')]
     1006        self.service.notifyDelete(JID('pubsub.example.org'), 'test',
     1007                                  subscriptions, redirectURI)
     1008        message = self.stub.output[-1]
     1009
     1010        self.assertEquals('message', message.name)
     1011        self.assertIdentical(None, message.uri)
     1012        self.assertEquals('user@example.org', message['to'])
     1013        self.assertEquals('pubsub.example.org', message['from'])
     1014        self.assertTrue(message.event)
     1015        self.assertEqual(NS_PUBSUB_EVENT, message.event.uri)
     1016        self.assertTrue(message.event.delete)
     1017        self.assertEqual(NS_PUBSUB_EVENT, message.event.delete.uri)
     1018        self.assertTrue(message.event.delete.hasAttribute('node'))
     1019        self.assertEqual('test', message.event.delete['node'])
     1020        self.assertTrue(message.event.delete.redirect)
     1021        self.assertEqual(NS_PUBSUB_EVENT, message.event.delete.redirect.uri)
     1022        self.assertTrue(message.event.delete.redirect.hasAttribute('uri'))
     1023        self.assertEqual(redirectURI, message.event.delete.redirect['uri'])
Note: See TracChangeset for help on using the changeset viewer.