source: wokkel/test/test_generic.py @ 96:8e6130587088

Last change on this file since 96:8e6130587088 was 96:8e6130587088, checked in by Ralph Meijer <ralphm@…>, 10 years ago

Remove copyright dates from individual source files, only update LICENSE.

  • Property exe set to *
File size: 2.7 KB
Line 
1# Copyright (c) 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]))
51
52
53
54class XmlPipeTest(unittest.TestCase):
55    """
56    Tests for L{wokkel.generic.XmlPipe}.
57    """
58
59    def setUp(self):
60        self.pipe = generic.XmlPipe()
61
62
63    def test_sendFromSource(self):
64        """
65        Send an element from the source and observe it from the sink.
66        """
67        def cb(obj):
68            called.append(obj)
69
70        called = []
71        self.pipe.sink.addObserver('/test[@xmlns="testns"]', cb)
72        element = domish.Element(('testns', 'test'))
73        self.pipe.source.send(element)
74        self.assertEquals([element], called)
75
76
77    def test_sendFromSink(self):
78        """
79        Send an element from the sink and observe it from the source.
80        """
81        def cb(obj):
82            called.append(obj)
83
84        called = []
85        self.pipe.source.addObserver('/test[@xmlns="testns"]', cb)
86        element = domish.Element(('testns', 'test'))
87        self.pipe.sink.send(element)
88        self.assertEquals([element], called)
Note: See TracBrowser for help on using the repository browser.