Ignore:
Timestamp:
Mar 7, 2011, 7:40:16 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Track change in Twisted Words, to pass a reason Failure with STREAM_END_EVENT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_subprotocols.py

    r96 r98  
    1111from twisted.test import proto_helpers
    1212from twisted.internet import defer
     13from twisted.python import failure
    1314from twisted.words.xish import domish
    1415from twisted.words.protocols.jabber import error, xmlstream
     
    5354    def connectionLost(self, reason):
    5455        self.doneLost += 1
     56
     57
     58
     59class FailureReasonXMPPHandler(subprotocols.XMPPHandler):
     60    """
     61    Dummy handler specifically for failure Reason tests.
     62    """
     63    def __init__(self):
     64        self.gotFailureReason = False
     65
     66
     67    def connectionLost(self, reason):
     68        if isinstance(reason, failure.Failure):
     69            self.gotFailureReason = True
    5570
    5671
     
    235250    def test_disconnected(self):
    236251        """
    237         Test that protocol handlers have their connectionLost method
    238         called when the XML stream is disconnected.
    239         """
    240         sm = self.streamManager
    241         handler = DummyXMPPHandler()
    242         handler.setHandlerParent(sm)
    243         xs = xmlstream.XmlStream(xmlstream.Authenticator())
    244         sm._disconnected(xs)
     252        Protocol handlers have connectionLost called on stream disconnect.
     253        """
     254        sm = self.streamManager
     255        handler = DummyXMPPHandler()
     256        handler.setHandlerParent(sm)
     257        sm._disconnected(None)
    245258        self.assertEquals(0, handler.doneMade)
    246259        self.assertEquals(0, handler.doneInitialized)
    247260        self.assertEquals(1, handler.doneLost)
     261
     262
     263    def test_disconnectedReason(self):
     264        """
     265        A L{STREAM_END_EVENT} results in L{StreamManager} firing the handlers
     266        L{connectionLost} methods, passing a L{failure.Failure} reason.
     267        """
     268        sm = self.streamManager
     269        handler = FailureReasonXMPPHandler()
     270        handler.setHandlerParent(sm)
     271        xs = xmlstream.XmlStream(xmlstream.Authenticator())
     272        sm._disconnected(failure.Failure(Exception("no reason")))
     273        self.assertEquals(True, handler.gotFailureReason)
    248274
    249275
Note: See TracChangeset for help on using the changeset viewer.