Changeset 45:125f9d902a20 for wokkel/test/test_subprotocols.py
- Timestamp:
- Nov 1, 2008, 7:18:50 PM (14 years ago)
- Branch:
- default
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@134
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/test/test_subprotocols.py
r4 r45 5 5 Tests for L{wokkel.subprotocols} 6 6 """ 7 8 from zope.interface.verify import verifyObject 7 9 8 10 from twisted.trial import unittest … … 12 14 from twisted.words.protocols.jabber import error, xmlstream 13 15 14 from wokkel import subprotocols16 from wokkel import iwokkel, subprotocols 15 17 16 18 class DummyFactory(object): 19 """ 20 Dummy XmlStream factory that only registers bootstrap observers. 21 """ 17 22 def __init__(self): 18 23 self.callbacks = {} 19 24 25 20 26 def addBootstrap(self, event, callback): 21 27 self.callbacks[event] = callback 22 28 23 29 30 24 31 class DummyXMPPHandler(subprotocols.XMPPHandler): 32 """ 33 Dummy XMPP subprotocol handler to count the methods are called on it. 34 """ 25 35 def __init__(self): 26 36 self.doneMade = 0 … … 28 38 self.doneLost = 0 29 39 40 30 41 def makeConnection(self, xs): 31 42 self.connectionMade() 32 43 44 33 45 def connectionMade(self): 34 46 self.doneMade += 1 35 47 48 36 49 def connectionInitialized(self): 37 50 self.doneInitialized += 1 38 51 52 39 53 def connectionLost(self, reason): 40 54 self.doneLost += 1 41 55 42 56 57 43 58 class XMPPHandlerTest(unittest.TestCase): 59 """ 60 Tests for L{subprotocols.XMPPHandler}. 61 """ 62 63 def test_interface(self): 64 """ 65 L{xmlstream.XMPPHandler} implements L{iwokkel.IXMPPHandler}. 66 """ 67 verifyObject(iwokkel.IXMPPHandler, subprotocols.XMPPHandler()) 68 44 69 45 70 def test_send(self): … … 47 72 Test that data is passed on for sending by the stream manager. 48 73 """ 49 50 74 class DummyStreamManager(object): 51 75 def __init__(self): … … 61 85 62 86 87 def test_makeConnection(self): 88 """ 89 Test that makeConnection saves the XML stream and calls connectionMade. 90 """ 91 class TestXMPPHandler(subprotocols.XMPPHandler): 92 def connectionMade(self): 93 self.doneMade = True 94 95 handler = TestXMPPHandler() 96 xs = xmlstream.XmlStream(xmlstream.Authenticator()) 97 handler.makeConnection(xs) 98 self.assertTrue(handler.doneMade) 99 self.assertIdentical(xs, handler.xmlstream) 100 101 102 def test_connectionLost(self): 103 """ 104 Test that connectionLost forgets the XML stream. 105 """ 106 handler = subprotocols.XMPPHandler() 107 xs = xmlstream.XmlStream(xmlstream.Authenticator()) 108 handler.makeConnection(xs) 109 handler.connectionLost(Exception()) 110 self.assertIdentical(None, handler.xmlstream) 111 112 113 114 class XMPPHandlerCollectionTest(unittest.TestCase): 115 """ 116 Tests for L{subprotocols.XMPPHandlerCollection}. 117 """ 118 119 def setUp(self): 120 self.collection = subprotocols.XMPPHandlerCollection() 121 122 123 def test_interface(self): 124 """ 125 L{subprotocols.StreamManager} implements L{iwokkel.IXMPPHandlerCollection}. 126 """ 127 verifyObject(iwokkel.IXMPPHandlerCollection, self.collection) 128 129 130 def test_addHandler(self): 131 """ 132 Test the addition of a protocol handler. 133 """ 134 handler = DummyXMPPHandler() 135 handler.setHandlerParent(self.collection) 136 self.assertIn(handler, self.collection) 137 self.assertIdentical(self.collection, handler.parent) 138 139 140 def test_removeHandler(self): 141 """ 142 Test removal of a protocol handler. 143 """ 144 handler = DummyXMPPHandler() 145 handler.setHandlerParent(self.collection) 146 handler.disownHandlerParent(self.collection) 147 self.assertNotIn(handler, self.collection) 148 self.assertIdentical(None, handler.parent) 149 150 151 63 152 class StreamManagerTest(unittest.TestCase): 153 """ 154 Tests for L{subprotocols.StreamManager}. 155 """ 64 156 65 157 def setUp(self): … … 83 175 sm.factory.callbacks['//event/xmpp/initfailed']) 84 176 85 def test__connected(self): 177 178 def test_connected(self): 86 179 """ 87 180 Test that protocol handlers have their connectionMade method called … … 97 190 self.assertEquals(0, handler.doneLost) 98 191 99 def test__authd(self): 192 193 def test_connectedLogTrafficFalse(self): 194 """ 195 Test raw data functions unset when logTraffic is set to False. 196 """ 197 sm = self.streamManager 198 handler = DummyXMPPHandler() 199 handler.setHandlerParent(sm) 200 xs = xmlstream.XmlStream(xmlstream.Authenticator()) 201 sm._connected(xs) 202 self.assertIdentical(None, xs.rawDataInFn) 203 self.assertIdentical(None, xs.rawDataOutFn) 204 205 206 def test_connectedLogTrafficTrue(self): 207 """ 208 Test raw data functions set when logTraffic is set to True. 209 """ 210 sm = self.streamManager 211 sm.logTraffic = True 212 handler = DummyXMPPHandler() 213 handler.setHandlerParent(sm) 214 xs = xmlstream.XmlStream(xmlstream.Authenticator()) 215 sm._connected(xs) 216 self.assertNotIdentical(None, xs.rawDataInFn) 217 self.assertNotIdentical(None, xs.rawDataOutFn) 218 219 220 def test_authd(self): 100 221 """ 101 222 Test that protocol handlers have their connectionInitialized method … … 111 232 self.assertEquals(0, handler.doneLost) 112 233 113 def test__disconnected(self): 234 235 def test_disconnected(self): 114 236 """ 115 237 Test that protocol handlers have their connectionLost method … … 125 247 self.assertEquals(1, handler.doneLost) 126 248 249 127 250 def test_addHandler(self): 128 251 """ … … 132 255 handler = DummyXMPPHandler() 133 256 handler.setHandlerParent(sm) 134 self.assertIn(handler, sm)135 self.assertIdentical(sm, handler.parent)136 257 137 258 self.assertEquals(0, handler.doneMade) 138 259 self.assertEquals(0, handler.doneInitialized) 139 260 self.assertEquals(0, handler.doneLost) 261 140 262 141 263 def test_addHandlerInitialized(self): … … 188 310 self.assertEquals("<presence/>", xs.transport.value()) 189 311 312 190 313 def test_sendNotConnected(self): 191 314 """ … … 216 339 217 340 self.assertEquals("<presence/>", xs.transport.value()) 218 self.failIf(sm._packetQueue) 341 self.assertFalse(sm._packetQueue) 342 219 343 220 344 def test_sendNotInitialized(self): … … 236 360 self.assertEquals("<presence/>", sm._packetQueue[0]) 237 361 362 238 363 def test_sendDisconnected(self): 239 364 """ … … 258 383 259 384 385 260 386 class DummyIQHandler(subprotocols.IQHandlerMixin): 261 387 iqHandlers = {'/iq[@type="get"]': 'onGet'}
Note: See TracChangeset
for help on using the changeset viewer.