Changeset 44:2c222a21d538 for wokkel
- Timestamp:
- Nov 1, 2008, 11:37:16 AM (14 years ago)
- Branch:
- default
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@133
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/compat.py
r38 r44 56 56 C{observerfn} arguments to L{utility.EventDispatcher.addObserver}. 57 57 58 @since: 8.2. 58 59 @ivar bootstraps: The list of registered bootstrap event observers. 59 60 @type bootstrap: C{list} … … 78 79 """ 79 80 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. 80 85 """ 81 86 self.bootstraps.append((event, fn)) … … 85 90 """ 86 91 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. 87 96 """ 88 97 self.bootstraps.remove((event, fn)) -
wokkel/test/test_compat.py
r38 r44 47 47 Dispatching an event should fire registered bootstrap observers. 48 48 """ 49 d = defer.Deferred() 49 called = [] 50 51 def cb(data): 52 called.append(data) 53 50 54 dispatcher = DummyProtocol() 51 self.factory.addBootstrap('//event/myevent', d.callback)55 self.factory.addBootstrap('//event/myevent', cb) 52 56 self.factory.installBootstraps(dispatcher) 57 53 58 dispatcher.dispatch(None, '//event/myevent') 54 return d59 self.assertEquals(1, len(called)) 55 60 56 61 … … 59 64 Test addition and removal of a bootstrap event handler. 60 65 """ 61 def cb(self): 62 pass 66 67 called = [] 68 69 def cb(data): 70 called.append(data) 63 71 64 72 self.factory.addBootstrap('//event/myevent', cb) 65 self.assertIn(('//event/myevent', cb), self.factory.bootstraps)66 67 73 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) 69 80 70 81 … … 148 159 Set up a server factory with a authenticator factory function. 149 160 """ 161 class TestAuthenticator(object): 162 def __init__(self): 163 self.xmlstreams = [] 164 165 def associateWithStream(self, xs): 166 self.xmlstreams.append(xs) 167 150 168 def authenticatorFactory(): 151 return xmlstream.Authenticator()169 return TestAuthenticator() 152 170 153 171 self.factory = XmlStreamServerFactory(authenticatorFactory) … … 161 179 162 180 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) 172 200 self.assertIsInstance(xs, xmlstream.XmlStream) 173 self.assertIsInstance(xs.authenticator, xmlstream.Authenticator)174 201 175 202 … … 183 210 self.assertNotIdentical(xs1, xs2) 184 211 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.