source: wokkel/test/test_disco.py @ 1:677f7d3cca75

Last change on this file since 1:677f7d3cca75 was 1:677f7d3cca75, checked in by Ralph Meijer <ralphm@…>, 14 years ago

Initial, heavily worked around code drop from the idavoll and mimir projects.

File size: 1.4 KB
Line 
1# Copyright (c) 2003-2007 Ralph Meijer
2# See LICENSE for details.
3
4"""
5Tests for L{wokkel.disco}.
6"""
7
8from twisted.internet import defer
9from twisted.test import proto_helpers
10from twisted.trial import unittest
11from twisted.words.xish.xmlstream import XmlStreamFactory
12from zope.interface import implements
13
14from wokkel.subprotocols import XMPPHandler, StreamManager
15
16from wokkel import disco
17
18NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'
19NS_DISCO_ITEMS = 'http://jabber.org/protocol/disco#items'
20
21class DiscoResponder(XMPPHandler):
22    implements(disco.IDisco)
23
24    def getDiscoInfo(self, nodeIdentifier):
25        if nodeIdentifier is None:
26            return defer.succeed([
27                disco.Identity('dummy', 'generic', 'Generic Dummy Entity'),
28                disco.Feature('jabber:iq:version')
29            ])
30        else:
31            return defer.succeed([])
32
33class DiscoHandlerTest(unittest.TestCase):
34    def test_DiscoInfo(self):
35        factory = XmlStreamFactory()
36        sm = StreamManager(factory)
37        sm.addHandler(disco.DiscoHandler())
38        sm.addHandler(DiscoResponder())
39        xs = factory.buildProtocol(None)
40        xs.transport = proto_helpers.StringTransport()
41        xs.connectionMade()
42        xs.dataReceived("<stream>")
43        xs.dataReceived("""<iq from='test@example.com' type='get'>
44                             <query xmlns='%s'/>
45                           </iq>""" % NS_DISCO_INFO)
Note: See TracBrowser for help on using the repository browser.