source: wokkel/test/test_disco.py @ 30:68535ae85c8d

Last change on this file since 30:68535ae85c8d was 30:68535ae85c8d, checked in by Ralph Meijer <ralphm@…>, 13 years ago

Add support for pubsub collections.

File size: 2.0 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.trial import unittest
10from twisted.words.xish.xmlstream import XmlStreamFactory
11from zope.interface import implements
12
13from wokkel.subprotocols import XMPPHandler, StreamManager
14
15from wokkel import disco
16
17NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'
18NS_DISCO_ITEMS = 'http://jabber.org/protocol/disco#items'
19
20class DiscoResponder(XMPPHandler):
21    implements(disco.IDisco)
22
23    def getDiscoInfo(self, requestor, target, nodeIdentifier):
24        if not nodeIdentifier:
25            return defer.succeed([
26                disco.DiscoIdentity('dummy', 'generic', 'Generic Dummy Entity'),
27                disco.DiscoFeature('jabber:iq:version')
28            ])
29        else:
30            return defer.succeed([])
31
32class DiscoHandlerTest(unittest.TestCase):
33    def test_DiscoInfo(self):
34        factory = XmlStreamFactory()
35        sm = StreamManager(factory)
36        disco.DiscoHandler().setHandlerParent(sm)
37        DiscoResponder().setHandlerParent(sm)
38        xs = factory.buildProtocol(None)
39        output = []
40        xs.send = output.append
41        xs.connectionMade()
42        xs.dispatch(xs, "//event/stream/authd")
43        xs.dataReceived("<stream>")
44        xs.dataReceived("""<iq from='test@example.com' to='example.com'
45                               type='get'>
46                             <query xmlns='%s'/>
47                           </iq>""" % NS_DISCO_INFO)
48        reply = output[0]
49        self.assertEqual(NS_DISCO_INFO, reply.query.uri)
50        self.assertEqual(NS_DISCO_INFO, reply.query.identity.uri)
51        self.assertEqual('dummy', reply.query.identity['category'])
52        self.assertEqual('generic', reply.query.identity['type'])
53        self.assertEqual('Generic Dummy Entity', reply.query.identity['name'])
54        self.assertEqual(NS_DISCO_INFO, reply.query.feature.uri)
55        self.assertEqual('jabber:iq:version', reply.query.feature['var'])
56
Note: See TracBrowser for help on using the repository browser.