Changeset 39:a9e354f69018 for wokkel/test/test_component.py
- Timestamp:
- Oct 11, 2008, 10:41:03 PM (14 years ago)
- Branch:
- default
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@106
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/test/test_component.py
r35 r39 6 6 """ 7 7 8 from zope.interface.verify import verifyObject 9 10 from twisted.internet import defer 8 11 from twisted.python import failure 9 12 from twisted.trial import unittest 10 from twisted.words.protocols.jabber import xmlstream13 from twisted.words.protocols.jabber import ijabber, xmlstream 11 14 from twisted.words.protocols.jabber.jid import JID 12 15 from twisted.words.xish import domish … … 14 17 from wokkel import component 15 18 from wokkel.generic import XmlPipe 19 20 class InternalComponentTest(unittest.TestCase): 21 """ 22 Tests for L{component.InternalComponent}. 23 """ 24 25 def setUp(self): 26 self.router = component.RouterService() 27 self.component = component.InternalComponent(self.router, 'component') 28 29 30 def test_interface(self): 31 """ 32 L{component.InternalComponent} implements 33 L{ijabber.IXMPPHandlerCollection}. 34 """ 35 verifyObject(ijabber.IXMPPHandlerCollection, self.component) 36 37 38 def test_startService(self): 39 """ 40 Starting the service creates a new route and hooks up handlers. 41 """ 42 43 events = [] 44 45 class TestHandler(xmlstream.XMPPHandler): 46 47 def connectionInitialized(self): 48 fn = lambda obj: events.append(obj) 49 self.xmlstream.addObserver('//event/test', fn) 50 51 TestHandler().setHandlerParent(self.component) 52 53 self.assertFalse(self.component.running) 54 55 self.component.startService() 56 57 self.assertTrue(self.component.running) 58 self.assertIn('component', self.router.routes) 59 60 self.assertEquals([], events) 61 self.component.xmlstream.dispatch(None, '//event/test') 62 self.assertEquals([None], events) 63 64 65 def test_stopService(self): 66 """ 67 Stopping the service removes the route and disconnects handlers. 68 """ 69 70 events = [] 71 72 class TestHandler(xmlstream.XMPPHandler): 73 74 def connectionLost(self, reason): 75 events.append(reason) 76 77 TestHandler().setHandlerParent(self.component) 78 79 self.component.startService() 80 self.component.stopService() 81 82 self.assertFalse(self.component.running) 83 self.assertEquals(1, len(events)) 84 self.assertNotIn('component', self.router.routes) 85 86 87 def test_addHandler(self): 88 """ 89 Adding a handler connects it to the stream. 90 """ 91 events = [] 92 93 class TestHandler(xmlstream.XMPPHandler): 94 95 def connectionInitialized(self): 96 fn = lambda obj: events.append(obj) 97 self.xmlstream.addObserver('//event/test', fn) 98 99 self.component.startService() 100 self.component.xmlstream.dispatch(None, '//event/test') 101 self.assertEquals([], events) 102 103 TestHandler().setHandlerParent(self.component) 104 self.component.xmlstream.dispatch(None, '//event/test') 105 self.assertEquals([None], events) 106 107 108 def test_send(self): 109 """ 110 A message sent from the component ends up at the router. 111 """ 112 events = [] 113 fn = lambda obj: events.append(obj) 114 message = domish.Element((None, 'message')) 115 116 self.component.startService() 117 self.router.routes['component'].addObserver('/message', fn) 118 self.component.send(message) 119 120 self.assertEquals([message], events) 121 122 16 123 17 124 class RouterServiceTest(unittest.TestCase):
Note: See TracChangeset
for help on using the changeset viewer.