Changeset 44:2c222a21d538


Ignore:
Timestamp:
Nov 1, 2008, 11:37:16 AM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@133
Message:

Bring compat in line with Twisted trunk regarding XmlStreamServerFactory?.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/compat.py

    r38 r44  
    5656    C{observerfn} arguments to L{utility.EventDispatcher.addObserver}.
    5757
     58    @since: 8.2.
    5859    @ivar bootstraps: The list of registered bootstrap event observers.
    5960    @type bootstrap: C{list}
     
    7879        """
    7980        Add a bootstrap event handler.
     81
     82        @param event: The event to register an observer for.
     83        @type event: C{str} or L{xpath.XPathQuery}
     84        @param fn: The observer callable to be registered.
    8085        """
    8186        self.bootstraps.append((event, fn))
     
    8590        """
    8691        Remove a bootstrap event handler.
     92
     93        @param event: The event the observer is registered for.
     94        @type event: C{str} or L{xpath.XPathQuery}
     95        @param fn: The registered observer callable.
    8796        """
    8897        self.bootstraps.remove((event, fn))
  • wokkel/test/test_compat.py

    r38 r44  
    4747        Dispatching an event should fire registered bootstrap observers.
    4848        """
    49         d = defer.Deferred()
     49        called = []
     50
     51        def cb(data):
     52            called.append(data)
     53
    5054        dispatcher = DummyProtocol()
    51         self.factory.addBootstrap('//event/myevent', d.callback)
     55        self.factory.addBootstrap('//event/myevent', cb)
    5256        self.factory.installBootstraps(dispatcher)
     57
    5358        dispatcher.dispatch(None, '//event/myevent')
    54         return d
     59        self.assertEquals(1, len(called))
    5560
    5661
     
    5964        Test addition and removal of a bootstrap event handler.
    6065        """
    61         def cb(self):
    62             pass
     66
     67        called = []
     68
     69        def cb(data):
     70            called.append(data)
    6371
    6472        self.factory.addBootstrap('//event/myevent', cb)
    65         self.assertIn(('//event/myevent', cb), self.factory.bootstraps)
    66 
    6773        self.factory.removeBootstrap('//event/myevent', cb)
    68         self.assertNotIn(('//event/myevent', cb), self.factory.bootstraps)
     74
     75        dispatcher = DummyProtocol()
     76        self.factory.installBootstraps(dispatcher)
     77
     78        dispatcher.dispatch(None, '//event/myevent')
     79        self.assertFalse(called)
    6980
    7081
     
    148159        Set up a server factory with a authenticator factory function.
    149160        """
     161        class TestAuthenticator(object):
     162            def __init__(self):
     163                self.xmlstreams = []
     164
     165            def associateWithStream(self, xs):
     166                self.xmlstreams.append(xs)
     167
    150168        def authenticatorFactory():
    151             return xmlstream.Authenticator()
     169            return TestAuthenticator()
    152170
    153171        self.factory = XmlStreamServerFactory(authenticatorFactory)
     
    161179
    162180
    163     def test_buildProtocol(self):
    164         """
    165         The authenticator factory should be passed to its protocol and it
    166         should instantiate the authenticator and save it.
    167         L{xmlstream.XmlStream}s do that, but we also want to ensure it really
    168         is one.
    169         """
    170         xs = self.factory.buildProtocol(None)
    171         self.assertIdentical(self.factory, xs.factory)
     181    def test_buildProtocolAuthenticatorInstantiation(self):
     182        """
     183        The authenticator factory should be used to instantiate the
     184        authenticator and pass it to the protocol.
     185
     186        The default protocol, L{XmlStream} stores the authenticator it is
     187        passed, and calls its C{associateWithStream} method. so we use that to
     188        check whether our authenticator factory is used and the protocol
     189        instance gets an authenticator.
     190        """
     191        xs = self.factory.buildProtocol(None)
     192        self.assertEquals([xs], xs.authenticator.xmlstreams)
     193
     194
     195    def test_buildProtocolXmlStream(self):
     196        """
     197        The protocol factory creates Jabber XML Stream protocols by default.
     198        """
     199        xs = self.factory.buildProtocol(None)
    172200        self.assertIsInstance(xs, xmlstream.XmlStream)
    173         self.assertIsInstance(xs.authenticator, xmlstream.Authenticator)
    174201
    175202
     
    183210        self.assertNotIdentical(xs1, xs2)
    184211        self.assertNotIdentical(xs1.authenticator, xs2.authenticator)
     212
     213
     214    def test_buildProtocolInstallsBootstraps(self):
     215        """
     216        The protocol factory installs bootstrap event handlers on the protocol.
     217        """
     218        called = []
     219
     220        def cb(data):
     221            called.append(data)
     222
     223        self.factory.addBootstrap('//event/myevent', cb)
     224
     225        xs = self.factory.buildProtocol(None)
     226        xs.dispatch(None, '//event/myevent')
     227
     228        self.assertEquals(1, len(called))
     229
     230
     231    def test_buildProtocolStoresFactory(self):
     232        """
     233        The protocol factory is saved in the protocol.
     234        """
     235        xs = self.factory.buildProtocol(None)
     236        self.assertIdentical(self.factory, xs.factory)
Note: See TracChangeset for help on using the changeset viewer.