source: wokkel/test/test_disco.py @ 31:45f3d59431c2

Last change on this file since 31:45f3d59431c2 was 31:45f3d59431c2, checked in by Ralph Meijer <ralphm@…>, 14 years ago

Release Wokkel 0.4.0.

File size: 2.0 KB
RevLine 
[31]1# Copyright (c) 2003-2008 Ralph Meijer
[1]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
[6]23    def getDiscoInfo(self, requestor, target, nodeIdentifier):
[30]24        if not nodeIdentifier:
[1]25            return defer.succeed([
[6]26                disco.DiscoIdentity('dummy', 'generic', 'Generic Dummy Entity'),
27                disco.DiscoFeature('jabber:iq:version')
[1]28            ])
29        else:
30            return defer.succeed([])
31
32class DiscoHandlerTest(unittest.TestCase):
33    def test_DiscoInfo(self):
34        factory = XmlStreamFactory()
35        sm = StreamManager(factory)
[6]36        disco.DiscoHandler().setHandlerParent(sm)
37        DiscoResponder().setHandlerParent(sm)
[1]38        xs = factory.buildProtocol(None)
[6]39        output = []
40        xs.send = output.append
[1]41        xs.connectionMade()
[6]42        xs.dispatch(xs, "//event/stream/authd")
[1]43        xs.dataReceived("<stream>")
[6]44        xs.dataReceived("""<iq from='test@example.com' to='example.com'
45                               type='get'>
[1]46                             <query xmlns='%s'/>
47                           </iq>""" % NS_DISCO_INFO)
[6]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.