source: wokkel/test/test_xmppim.py @ 17:d42fd6c92576

Last change on this file since 17:d42fd6c92576 was 9:ba3ccb5699fc, checked in by Ralph Meijer <ralphm@…>, 15 years ago

Fix sending unavailable presence.

Author: ralphm.
Fixes #3.

File size: 2.4 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 wokkel import xmppim
11
12class PresenceClientProtocolTest(unittest.TestCase):
13    def setUp(self):
14        self.output = []
15        self.protocol = xmppim.PresenceClientProtocol()
16        self.protocol.parent = self
17
18    def send(self, obj):
19        self.output.append(obj)
20
21    def test_unavailableDirected(self):
22        """
23        Test sending of directed unavailable presence broadcast.
24        """
25
26        self.protocol.unavailable(JID('user@example.com'))
27        presence = self.output[-1]
28        self.assertEquals("presence", presence.name)
29        self.assertEquals(None, presence.uri)
30        self.assertEquals("user@example.com", presence.getAttribute('to'))
31        self.assertEquals("unavailable", presence.getAttribute('type'))
32
33    def test_unavailableWithStatus(self):
34        """
35        Test sending of directed unavailable presence broadcast with status.
36        """
37
38        self.protocol.unavailable(JID('user@example.com'),
39                                  {None: 'Disconnected'})
40        presence = self.output[-1]
41        self.assertEquals("presence", presence.name)
42        self.assertEquals(None, presence.uri)
43        self.assertEquals("user@example.com", presence.getAttribute('to'))
44        self.assertEquals("unavailable", presence.getAttribute('type'))
45        self.assertEquals("Disconnected", unicode(presence.status))
46
47    def test_unavailableBroadcast(self):
48        """
49        Test sending of unavailable presence broadcast.
50        """
51
52        self.protocol.unavailable(None)
53        presence = self.output[-1]
54        self.assertEquals("presence", presence.name)
55        self.assertEquals(None, presence.uri)
56        self.assertEquals(None, presence.getAttribute('to'))
57        self.assertEquals("unavailable", presence.getAttribute('type'))
58
59    def test_unavailableBroadcastNoEntityParameter(self):
60        """
61        Test sending of unavailable presence broadcast by not passing entity.
62        """
63
64        self.protocol.unavailable()
65        presence = self.output[-1]
66        self.assertEquals("presence", presence.name)
67        self.assertEquals(None, presence.uri)
68        self.assertEquals(None, presence.getAttribute('to'))
69        self.assertEquals("unavailable", presence.getAttribute('type'))
Note: See TracBrowser for help on using the repository browser.