source: wokkel/test/test_generic.py @ 20:480ba9e6ee3c

Last change on this file since 20:480ba9e6ee3c was 20:480ba9e6ee3c, checked in by Ralph Meijer <ralphm@…>, 15 years ago

Fix broken version handler.

File size: 1.7 KB
Line 
1# Copyright (c) 2003-2008 Ralph Meijer
2# See LICENSE for details.
3
4"""
5Tests for L{wokkel.generic}.
6"""
7
8from twisted.trial import unittest
9from twisted.words.xish import domish
10
11from wokkel import generic
12from wokkel.test.helpers import XmlStreamStub
13
14NS_VERSION = 'jabber:iq:version'
15
16class VersionHandlerTest(unittest.TestCase):
17    """
18    Tests for L{wokkel.generic.VersionHandler}.
19    """
20
21    def test_onVersion(self):
22        """
23        Test response to incoming version request.
24        """
25        self.stub = XmlStreamStub()
26        self.protocol = generic.VersionHandler('Test', '0.1.0')
27        self.protocol.xmlstream = self.stub.xmlstream
28        self.protocol.send = self.stub.xmlstream.send
29        self.protocol.connectionInitialized()
30
31        iq = domish.Element((None, 'iq'))
32        iq['from'] = 'user@example.org/Home'
33        iq['to'] = 'example.org'
34        iq['type'] = 'get'
35        query = iq.addElement((NS_VERSION, 'query'))
36        self.stub.send(iq)
37
38        response = self.stub.output[-1]
39        self.assertEquals('user@example.org/Home', response['to'])
40        self.assertEquals('example.org', response['from'])
41        self.assertEquals('result', response['type'])
42        self.assertEquals(NS_VERSION, response.query.uri)
43        elements = list(domish.generateElementsQNamed(response.query.children,
44                                                      'name', NS_VERSION))
45        self.assertEquals(1, len(elements))
46        self.assertEquals('Test', unicode(elements[0]))
47        elements = list(domish.generateElementsQNamed(response.query.children,
48                                                      'version', NS_VERSION))
49        self.assertEquals(1, len(elements))
50        self.assertEquals('0.1.0', unicode(elements[0]))
Note: See TracBrowser for help on using the repository browser.