source: wokkel/test/test_pubsub.py @ 4:e8e7d5543a6f

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

Reverse how handlers are associated with the stream manager. Kick version.

File size: 2.2 KB
Line 
1# Copyright (c) 2003-2007 Ralph Meijer
2# See LICENSE for details.
3
4"""
5Tests for L{wokkel.pubsub}
6"""
7
8from twisted.trial import unittest
9from twisted.words.xish import domish
10from twisted.words.protocols.jabber import error
11from twisted.words.protocols.jabber.jid import JID
12
13from wokkel import pubsub
14
15class PubSubServiceTest(unittest.TestCase):
16
17    def setUp(self):
18        self.output = []
19
20    def send(self, obj):
21        self.output.append(obj)
22
23    def test_onPublishNoNode(self):
24        handler = pubsub.PubSubService()
25        handler.parent = self
26        iq = domish.Element((None, 'iq'))
27        iq['from'] = 'user@example.org'
28        iq['type'] = 'set'
29        iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
30        iq.pubsub.addElement('publish')
31        handler.handleRequest(iq)
32
33        e = error.exceptionFromStanza(self.output[-1])
34        self.assertEquals('bad-request', e.condition)
35
36    def test_onPublish(self):
37        class Handler(pubsub.PubSubService):
38            def publish(self, *args, **kwargs):
39                self.args = args
40                self.kwargs = kwargs
41
42        handler = Handler()
43        handler.parent = self
44        iq = domish.Element((None, 'iq'))
45        iq['type'] = 'set'
46        iq['from'] = 'user@example.org'
47        iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
48        iq.pubsub.addElement('publish')
49        iq.pubsub.publish['node'] = 'test'
50        handler.handleRequest(iq)
51
52        self.assertEqual((JID('user@example.org'), 'test', []), handler.args)
53
54    def test_onOptionsGet(self):
55        handler = pubsub.PubSubService()
56        handler.parent = self
57        iq = domish.Element((None, 'iq'))
58        iq['from'] = 'user@example.org'
59        iq['type'] = 'get'
60        iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
61        iq.pubsub.addElement('options')
62        handler.handleRequest(iq)
63
64        e = error.exceptionFromStanza(self.output[-1])
65        self.assertEquals('feature-not-implemented', e.condition)
66        self.assertEquals('unsupported', e.appCondition.name)
67        self.assertEquals('http://jabber.org/protocol/pubsub#errors',
68                          e.appCondition.uri)
Note: See TracBrowser for help on using the repository browser.