Mercurial > libervia-backend
annotate src/test/test_core_xmpp.py @ 517:59b32c04e105
plugin text commands: added /help command
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Oct 2012 19:22:51 +0200 |
parents | 2a072735e459 |
children | ca13633d3b6b |
rev | line source |
---|---|
335 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
335 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
335 | 10 the Free Software Foundation, either version 3 of the License, or |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
335 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
335 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
22 from sat.test import helpers | |
23 from twisted.trial import unittest | |
24 from sat.core.sat_main import SAT | |
25 from sat.core import xmpp | |
26 from twisted.internet import defer | |
27 from twisted.words.protocols.jabber.jid import JID | |
28 from wokkel.generic import parseXml | |
29 from wokkel.xmppim import RosterItem | |
30 | |
31 | |
32 | |
33 class SatXMPPClientTest(unittest.TestCase): | |
34 | |
35 def setUp(self): | |
36 self.host = helpers.FakeSAT() | |
37 self.client = xmpp.SatXMPPClient(self.host, "test_profile", JID("test@example.org"), "test") | |
38 | |
39 def test_init(self): | |
40 """Check that init values are correctly initialised""" | |
41 self.assertEqual(self.client.profile, "test_profile") | |
42 print self.client.host | |
43 self.assertEqual(self.client.host_app, self.host) | |
44 self.assertTrue(isinstance(self.client.client_initialized, defer.Deferred)) | |
45 | |
46 class SatMessageProtocolTest(unittest.TestCase): | |
47 | |
48 def setUp(self): | |
49 self.host = helpers.FakeSAT() | |
50 self.message = xmpp.SatMessageProtocol(self.host) | |
51 self.message.parent = helpers.FakeParent() | |
52 | |
53 def test_onMessage(self): | |
54 xml = """ | |
55 <message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1"> | |
56 <body>test</body> | |
57 </message> | |
58 """ | |
59 stanza = parseXml(xml) | |
60 self.host.bridge.expectCall("newMessage", "sender@example.net/house", "test", "chat", u"test@example.org/SàT", profile="test_profile") | |
61 self.message.onMessage(stanza) | |
62 | |
63 class SatRosterProtocolTest(unittest.TestCase): | |
64 | |
65 def setUp(self): | |
66 self.host = helpers.FakeSAT() | |
67 self.roster = xmpp.SatRosterProtocol(self.host) | |
68 self.roster.parent = helpers.FakeParent() | |
69 | |
70 def test_onRosterSet(self): | |
71 roster_item = RosterItem(helpers.TEST_JID) | |
72 roster_item.name = u"Test Man" | |
73 roster_item.subscriptionTo = True | |
74 roster_item.subscriptionFrom = True | |
75 roster_item.ask = False | |
76 roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]) | |
77 self.host.bridge.expectCall("newContact", helpers.TEST_JID_STR, {'to':'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), "test_profile") | |
78 self.roster.onRosterSet(roster_item) | |
79 | |
80 class SatPresenceProtocolTest(unittest.TestCase): | |
81 | |
82 def setUp(self): | |
83 self.host = helpers.FakeSAT() | |
84 self.presence = xmpp.SatPresenceProtocol(self.host) | |
85 self.presence.parent = helpers.FakeParent() | |
86 | |
87 def test_availableReceived(self): | |
88 self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "xa", 15, {'default': "test status", 'fr':'statut de test'}, helpers.TEST_PROFILE) | |
89 self.presence.availableReceived(helpers.TEST_JID, 'xa', {None: "test status", 'fr':'statut de test'}, 15) | |
90 | |
91 def test_availableReceived_empty_statuses(self): | |
92 self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "xa", 15, {}, helpers.TEST_PROFILE) | |
93 self.presence.availableReceived(helpers.TEST_JID, 'xa', None, 15) | |
94 | |
95 def test_unavailableReceived(self): | |
96 self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "unavailable", 0, {}, helpers.TEST_PROFILE) | |
97 self.presence.unavailableReceived(helpers.TEST_JID, None) | |
98 | |
99 def test_subscribedReceived(self): | |
100 self.host.bridge.expectCall("subscribe", "subscribed", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) | |
101 self.presence.subscribedReceived(helpers.TEST_JID) | |
102 | |
103 def test_unsubscribedReceived(self): | |
104 self.host.bridge.expectCall("subscribe", "unsubscribed", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) | |
105 self.presence.unsubscribedReceived(helpers.TEST_JID) | |
106 | |
107 def test_subscribeReceived(self): | |
108 self.host.bridge.expectCall("subscribe", "subscribe", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) | |
109 self.presence.subscribeReceived(helpers.TEST_JID) | |
110 | |
111 def test_unsubscribeReceived(self): | |
112 self.host.bridge.expectCall("subscribe", "unsubscribe", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) | |
113 self.presence.unsubscribeReceived(helpers.TEST_JID) | |
114 |