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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.