Ignore:
Timestamp:
Dec 26, 2008, 2:40:11 PM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@140
Message:

If provided, return NodeID in the response for Service Discovery requests.

This also renames the namespace constants to include DISCO in their name
and provides better tests and docstrings.

Author: ralphm.
Reviewer: tofu.
Fixes #7.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/helpers.py

    r10 r46  
    66"""
    77
     8from twisted.internet import defer
     9from twisted.words.xish import xpath
    810from twisted.words.xish.utility import EventDispatcher
     11
     12from wokkel.generic import parseXml
    913
    1014class XmlStreamStub(object):
     
    5559        """
    5660        self.xmlstream.dispatch(obj)
     61
     62
     63class TestableRequestHandlerMixin(object):
     64    """
     65    Mixin for testing XMPPHandlers that process iq requests.
     66
     67    Handlers that use L{wokkel.subprotocols.IQHandlerMixin} define a
     68    C{iqHandlers} attribute that lists the handlers to be called for iq
     69    requests. This mixin provides L{handleRequest} to mimic the handler
     70    processing for easier testing.
     71    """
     72
     73    def handleRequest(self, xml):
     74        """
     75        Find a handler and call it directly.
     76
     77        @param xml: XML stanza that may yield a handler being called.
     78        @type xml: C{str}.
     79        @return: Deferred that fires with the result of a handler for this
     80                 stanza. If no handler was found, the deferred has its errback
     81                 called with a C{NotImplementedError} exception.
     82        """
     83        handler = None
     84        iq = parseXml(xml)
     85        for queryString, method in self.service.iqHandlers.iteritems():
     86            if xpath.internQuery(queryString).matches(iq):
     87                handler = getattr(self.service, method)
     88
     89        if handler:
     90            d = defer.maybeDeferred(handler, iq)
     91        else:
     92            d = defer.fail(NotImplementedError())
     93
     94        return d
Note: See TracChangeset for help on using the changeset viewer.