Ignore:
Timestamp:
Aug 4, 2008, 3:44:57 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@60
Message:

Add support for pubsub collections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_pubsub.py

    r29 r30  
    1414from twisted.words.protocols.jabber.jid import JID
    1515
    16 from wokkel import data_form, iwokkel, pubsub
     16from wokkel import data_form, iwokkel, pubsub, shim
    1717from wokkel.generic import parseXml
    1818from wokkel.test.helpers import XmlStreamStub
     
    8585            self.assertEquals('test', event.nodeIdentifier)
    8686            self.assertEquals([item1, item2, item3], event.items)
     87
     88        d, self.protocol.itemsReceived = calledAsync(itemsReceived)
     89        self.stub.send(message)
     90        return d
     91
     92
     93    def test_eventItemsCollection(self):
     94        """
     95        Test receiving an items event resulting in a call to itemsReceived.
     96        """
     97        message = domish.Element((None, 'message'))
     98        message['from'] = 'pubsub.example.org'
     99        message['to'] = 'user@example.org/home'
     100        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
     101        items = event.addElement('items')
     102        items['node'] = 'test'
     103
     104        headers = shim.Headers([('Collection', 'collection')])
     105        message.addChild(headers)
     106
     107        def itemsReceived(event):
     108            self.assertEquals(JID('user@example.org/home'), event.recipient)
     109            self.assertEquals(JID('pubsub.example.org'), event.sender)
     110            self.assertEquals('test', event.nodeIdentifier)
     111            self.assertEquals({'Collection': ['collection']}, event.headers)
    87112
    88113        d, self.protocol.itemsReceived = calledAsync(itemsReceived)
     
    574599                }
    575600
    576         def getDefaultConfiguration(requestor, service):
     601        def getDefaultConfiguration(requestor, service, nodeType):
    577602            self.assertEqual(JID('user@example.org'), requestor)
    578603            self.assertEqual(JID('pubsub.example.org'), service)
     604            self.assertEqual('leaf', nodeType)
    579605            return defer.succeed({})
    580606
     
    800826        d.addCallback(cb)
    801827        return d
     828
     829
     830    def test_onRetract(self):
     831        """
     832        A retract request should result in L{PubSubService.retract} being
     833        called.
     834        """
     835
     836        xml = """
     837        <iq type='set' to='pubsub.example.org'
     838                       from='user@example.org'>
     839          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
     840            <retract node='test'>
     841              <item id='item1'/>
     842              <item id='item2'/>
     843            </retract>
     844          </pubsub>
     845        </iq>
     846        """
     847
     848        def retract(requestor, service, nodeIdentifier, itemIdentifiers):
     849            self.assertEqual(JID('user@example.org'), requestor)
     850            self.assertEqual(JID('pubsub.example.org'), service)
     851            self.assertEqual('test', nodeIdentifier)
     852            self.assertEqual(['item1', 'item2'], itemIdentifiers)
     853            return defer.succeed(None)
     854
     855        self.service.retract = retract
     856        return self.handleRequest(xml)
     857
     858
     859    def test_onPurge(self):
     860        """
     861        A purge request should result in L{PubSubService.purge} being
     862        called.
     863        """
     864
     865        xml = """
     866        <iq type='set' to='pubsub.example.org'
     867                       from='user@example.org'>
     868          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
     869            <purge node='test'/>
     870          </pubsub>
     871        </iq>
     872        """
     873
     874        def purge(requestor, service, nodeIdentifier):
     875            self.assertEqual(JID('user@example.org'), requestor)
     876            self.assertEqual(JID('pubsub.example.org'), service)
     877            self.assertEqual('test', nodeIdentifier)
     878            return defer.succeed(None)
     879
     880        self.service.purge = purge
     881        return self.handleRequest(xml)
     882
     883
     884    def test_onDelete(self):
     885        """
     886        A delete request should result in L{PubSubService.delete} being
     887        called.
     888        """
     889
     890        xml = """
     891        <iq type='set' to='pubsub.example.org'
     892                       from='user@example.org'>
     893          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
     894            <delete node='test'/>
     895          </pubsub>
     896        </iq>
     897        """
     898
     899        def delete(requestor, service, nodeIdentifier):
     900            self.assertEqual(JID('user@example.org'), requestor)
     901            self.assertEqual(JID('pubsub.example.org'), service)
     902            self.assertEqual('test', nodeIdentifier)
     903            return defer.succeed(None)
     904
     905        self.service.delete = delete
     906        return self.handleRequest(xml)
Note: See TracChangeset for help on using the changeset viewer.