source: wokkel/test/test_pubsub.py @ 6:283b6997cf7d

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

Support services on a JID.

Author: ralphm
Fixes #2.

File size: 2.3 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['to'] = 'pubsub.example.org'
29        iq['type'] = 'set'
30        iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
31        iq.pubsub.addElement('publish')
32        handler.handleRequest(iq)
33
34        e = error.exceptionFromStanza(self.output[-1])
35        self.assertEquals('bad-request', e.condition)
36
37    def test_onPublish(self):
38        class Handler(pubsub.PubSubService):
39            def publish(self, *args, **kwargs):
40                self.args = args
41                self.kwargs = kwargs
42
43        handler = Handler()
44        handler.parent = self
45        iq = domish.Element((None, 'iq'))
46        iq['type'] = 'set'
47        iq['from'] = 'user@example.org'
48        iq['to'] = 'pubsub.example.org'
49        iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
50        iq.pubsub.addElement('publish')
51        iq.pubsub.publish['node'] = 'test'
52        handler.handleRequest(iq)
53
54        self.assertEqual((JID('user@example.org'),
55                          JID('pubsub.example.org'), 'test', []), handler.args)
56
57    def test_onOptionsGet(self):
58        handler = pubsub.PubSubService()
59        handler.parent = self
60        iq = domish.Element((None, 'iq'))
61        iq['from'] = 'user@example.org'
62        iq['to'] = 'pubsub.example.org'
63        iq['type'] = 'get'
64        iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
65        iq.pubsub.addElement('options')
66        handler.handleRequest(iq)
67
68        e = error.exceptionFromStanza(self.output[-1])
69        self.assertEquals('feature-not-implemented', e.condition)
70        self.assertEquals('unsupported', e.appCondition.name)
71        self.assertEquals('http://jabber.org/protocol/pubsub#errors',
72                          e.appCondition.uri)
Note: See TracBrowser for help on using the repository browser.