source: ralphm-patches/pubsub_disco_fixes.patch @ 34:e46c5701df9e

Last change on this file since 34:e46c5701df9e was 34:e46c5701df9e, checked in by Ralph Meijer <ralphm@…>, 11 years ago

Add a bunch of new patches.

File size: 7.6 KB
  • wokkel/disco.py

    diff -r 7740d56a1644 wokkel/disco.py
    a b  
    495495        """
    496496        Gather results from a list of deferreds.
    497497
    498         Similar to L{defer.gatherResults}, but flattens the returned results,
    499         consumes errors after the first one and fires the errback of the
    500         returned deferred with the failure of the first deferred that fires its
    501         errback.
     498        Similar to L{defer.gatherResults}, but flattens the returned results.
    502499
    503500        @param deferredList: List of deferreds for which the results should be
    504501                             gathered.
     
    512509                results.extend(value)
    513510            return results
    514511
    515         def eb(failure):
    516             failure.trap(defer.FirstError)
    517             return failure.value.subFailure
    518 
    519512        d = defer.DeferredList(deferredList, fireOnOneErrback=1,
    520513                                             consumeErrors=1)
    521         d.addCallbacks(cb, eb)
     514        d.addCallback(cb)
    522515        return d
    523516
    524517
  • wokkel/pubsub.py

    diff -r 7740d56a1644 wokkel/pubsub.py
    a b  
    10111011    @type pubSubFeatures: C{list} or C{None}
    10121012    """
    10131013
    1014     implements(IPubSubService)
     1014    implements(IPubSubService, disco.IDisco)
    10151015
    10161016    iqHandlers = {
    10171017            '/*': '_onPubSubRequest',
     
    10571057        self.xmlstream.addObserver(PUBSUB_REQUEST, self.handleRequest)
    10581058
    10591059
    1060     def getDiscoInfo(self, requestor, target, nodeIdentifier):
    1061         def toInfo(nodeInfo, info):
     1060    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
     1061        def toInfo(nodeInfo):
    10621062            if not nodeInfo:
    1063                 return info
     1063                return
    10641064
    10651065            (nodeType, metaData) = nodeInfo['type'], nodeInfo['meta-data']
    10661066            info.append(disco.DiscoIdentity('pubsub', nodeType))
     
    10801080
    10811081                info.append(form)
    10821082
    1083             return info
     1083            return
    10841084
    10851085        info = []
    10861086
     
    11061106                         for feature in features])
    11071107
    11081108        d = defer.maybeDeferred(getInfo, requestor, target, nodeIdentifier or '')
    1109         d.addCallback(toInfo, info)
     1109        d.addCallback(toInfo)
    11101110        d.addErrback(log.err)
     1111        d.addCallback(lambda _: info)
    11111112        return d
    11121113
    11131114
    1114     def getDiscoItems(self, requestor, target, nodeIdentifier):
     1115    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
    11151116        if self.hideNodes:
    11161117            d = defer.succeed([])
    11171118        elif self.resource is not None:
  • wokkel/test/test_disco.py

    diff -r 7740d56a1644 wokkel/test/test_disco.py
    a b  
    99
    1010from twisted.internet import defer
    1111from twisted.trial import unittest
     12from twisted.words.protocols.jabber.error import StanzaError
    1213from twisted.words.protocols.jabber.jid import JID
    1314from twisted.words.protocols.jabber.xmlstream import toResponse
    14 from twisted.words.xish import domish
     15from twisted.words.xish import domish, utility
    1516
    1617from wokkel import data_form, disco
    1718from wokkel.generic import parseXml
     
    596597        self.service = disco.DiscoHandler()
    597598
    598599
     600    def test_connectionInitializedObserveInfo(self):
     601        """
     602        An observer for Disco Info requests is setup on stream initialization.
     603        """
     604        xml = """<iq from='test@example.com' to='example.com'
     605                     type='get'>
     606                   <query xmlns='%s'/>
     607                 </iq>""" % NS_DISCO_INFO
     608
     609        def handleRequest(iq):
     610            called.append(iq)
     611
     612        called = []
     613        self.service.xmlstream = utility.EventDispatcher()
     614        self.service.handleRequest = handleRequest
     615        self.service.connectionInitialized()
     616        self.service.xmlstream.dispatch(parseXml(xml))
     617        self.assertEqual(1, len(called))
     618
     619
     620    def test_connectionInitializedObserveItems(self):
     621        """
     622        An observer for Disco Items requests is setup on stream initialization.
     623        """
     624        xml = """<iq from='test@example.com' to='example.com'
     625                     type='get'>
     626                   <query xmlns='%s'/>
     627                 </iq>""" % NS_DISCO_ITEMS
     628
     629        def handleRequest(iq):
     630            called.append(iq)
     631
     632        called = []
     633        self.service.xmlstream = utility.EventDispatcher()
     634        self.service.handleRequest = handleRequest
     635        self.service.connectionInitialized()
     636        self.service.xmlstream.dispatch(parseXml(xml))
     637        self.assertEqual(1, len(called))
     638
     639
    599640    def test_onDiscoInfo(self):
    600641        """
    601642        C{onDiscoInfo} should process an info request and return a response.
     
    661702        return d
    662703
    663704
     705    def test_onDiscoInfoWithNodeNoResults(self):
     706        """
     707        An info request for a node with no results returns items-not-found.
     708        """
     709        xml = """<iq from='test@example.com' to='example.com'
     710                     type='get'>
     711                   <query xmlns='%s' node='test'/>
     712                 </iq>""" % NS_DISCO_INFO
     713
     714        def cb(exc):
     715            self.assertEquals('item-not-found', exc.condition)
     716
     717        def info(requestor, target, nodeIdentifier):
     718            self.assertEqual('test', nodeIdentifier)
     719
     720            return defer.succeed([])
     721
     722        self.service.info = info
     723        d = self.handleRequest(xml)
     724        self.assertFailure(d, StanzaError)
     725        d.addCallback(cb)
     726        return d
     727
     728
    664729    def test_onDiscoItems(self):
    665730        """
    666731        C{onDiscoItems} should process an items request and return a response.
  • wokkel/test/test_pubsub.py

    diff -r 7740d56a1644 wokkel/test/test_pubsub.py
    a b  
    19031903        verify.verifyObject(iwokkel.IPubSubService, self.service)
    19041904
    19051905
     1906    def test_interfaceIDisco(self):
     1907        """
     1908        Do instances of L{pubsub.PubSubService} provide L{iwokkel.IDisco}?
     1909        """
     1910        verify.verifyObject(iwokkel.IDisco, self.service)
     1911
     1912
    19061913    def test_connectionMade(self):
    19071914        """
    19081915        Verify setup of observers in L{pubsub.connectionMade}.
     
    20092016        return d
    20102017
    20112018
     2019    def test_getDiscoInfoBadResponse(self):
     2020        """
     2021        If getInfo returns invalid response, it should be logged, then ignored.
     2022        """
     2023        def cb(info):
     2024            self.assertEquals([], info)
     2025            self.assertEqual(1, len(self.flushLoggedErrors(TypeError)))
     2026
     2027        def getInfo(requestor, target, nodeIdentifier):
     2028            return defer.succeed('bad response')
     2029
     2030        self.resource.getInfo = getInfo
     2031        d = self.service.getDiscoInfo(JID('user@example.org/home'),
     2032                                      JID('pubsub.example.org'), 'test')
     2033        d.addCallback(cb)
     2034        return d
     2035
     2036
     2037    def test_getDiscoInfoException(self):
     2038        """
     2039        If getInfo returns invalid response, it should be logged, then ignored.
     2040        """
     2041        def cb(info):
     2042            self.assertEquals([], info)
     2043            self.assertEqual(1, len(self.flushLoggedErrors(NotImplementedError)))
     2044
     2045        def getInfo(requestor, target, nodeIdentifier):
     2046            return defer.fail(NotImplementedError())
     2047
     2048        self.resource.getInfo = getInfo
     2049        d = self.service.getDiscoInfo(JID('user@example.org/home'),
     2050                                      JID('pubsub.example.org'), 'test')
     2051        d.addCallback(cb)
     2052        return d
     2053
     2054
    20122055    def test_getDiscoItemsRoot(self):
    20132056        """
    20142057        Test getDiscoItems on the root node.
Note: See TracBrowser for help on using the repository browser.