source: wokkel/test/test_xmppim.py @ 48:190498075c7f

Last change on this file since 48:190498075c7f was 28:65fd5f2bd59e, checked in by Ralph Meijer <ralphm@…>, 14 years ago

Add client side support for removing a roster item.

File size: 3.8 KB
Line 
1# Copyright (c) 2003-2008 Ralph Meijer
2# See LICENSE for details
3
4"""
5Tests for L{wokkel.xmppim}.
6"""
7
8from twisted.trial import unittest
9from twisted.words.protocols.jabber.jid import JID
10from twisted.words.protocols.jabber.xmlstream import toResponse
11from twisted.words.xish import domish
12
13from wokkel import xmppim
14from wokkel.test.helpers import XmlStreamStub
15
16NS_ROSTER = 'jabber:iq:roster'
17
18class PresenceClientProtocolTest(unittest.TestCase):
19    def setUp(self):
20        self.output = []
21        self.protocol = xmppim.PresenceClientProtocol()
22        self.protocol.parent = self
23
24    def send(self, obj):
25        self.output.append(obj)
26
27    def test_unavailableDirected(self):
28        """
29        Test sending of directed unavailable presence broadcast.
30        """
31
32        self.protocol.unavailable(JID('user@example.com'))
33        presence = self.output[-1]
34        self.assertEquals("presence", presence.name)
35        self.assertEquals(None, presence.uri)
36        self.assertEquals("user@example.com", presence.getAttribute('to'))
37        self.assertEquals("unavailable", presence.getAttribute('type'))
38
39    def test_unavailableWithStatus(self):
40        """
41        Test sending of directed unavailable presence broadcast with status.
42        """
43
44        self.protocol.unavailable(JID('user@example.com'),
45                                  {None: 'Disconnected'})
46        presence = self.output[-1]
47        self.assertEquals("presence", presence.name)
48        self.assertEquals(None, presence.uri)
49        self.assertEquals("user@example.com", presence.getAttribute('to'))
50        self.assertEquals("unavailable", presence.getAttribute('type'))
51        self.assertEquals("Disconnected", unicode(presence.status))
52
53    def test_unavailableBroadcast(self):
54        """
55        Test sending of unavailable presence broadcast.
56        """
57
58        self.protocol.unavailable(None)
59        presence = self.output[-1]
60        self.assertEquals("presence", presence.name)
61        self.assertEquals(None, presence.uri)
62        self.assertEquals(None, presence.getAttribute('to'))
63        self.assertEquals("unavailable", presence.getAttribute('type'))
64
65    def test_unavailableBroadcastNoEntityParameter(self):
66        """
67        Test sending of unavailable presence broadcast by not passing entity.
68        """
69
70        self.protocol.unavailable()
71        presence = self.output[-1]
72        self.assertEquals("presence", presence.name)
73        self.assertEquals(None, presence.uri)
74        self.assertEquals(None, presence.getAttribute('to'))
75        self.assertEquals("unavailable", presence.getAttribute('type'))
76
77
78class RosterClientProtocolTest(unittest.TestCase):
79    """
80    Tests for L{xmppim.RosterClientProtocol}.
81    """
82
83    def setUp(self):
84        self.stub = XmlStreamStub()
85        self.protocol = xmppim.RosterClientProtocol()
86        self.protocol.xmlstream = self.stub.xmlstream
87        self.protocol.connectionInitialized()
88
89
90    def test_removeItem(self):
91        """
92        Removing a roster item is setting an item with subscription C{remove}.
93        """
94        d = self.protocol.removeItem(JID('test@example.org'))
95
96        # Inspect outgoing iq request
97
98        iq = self.stub.output[-1]
99        self.assertEquals('set', iq.getAttribute('type'))
100        self.assertNotIdentical(None, iq.query)
101        self.assertEquals(NS_ROSTER, iq.query.uri)
102
103        children = list(domish.generateElementsQNamed(iq.query.children,
104                                                      'item', NS_ROSTER))
105        self.assertEquals(1, len(children))
106        child = children[0]
107        self.assertEquals('test@example.org', child['jid'])
108        self.assertEquals('remove', child['subscription'])
109
110        # Fake successful response
111
112        response = toResponse(iq, 'result')
113        self.stub.send(response)
114        return d
Note: See TracBrowser for help on using the repository browser.