Mercurial > libervia-backend
annotate src/test/test_plugin_xep_0085.py @ 1459:4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
/!\ not everything is working yet, and specially groupblogs are broken /!\
- renamed bridge api to use prefixed methods (e.g. psSubscribeToMany instead of subscribeToMany in PubSub)
- (xep-0060): try to find a default PubSub service, and put it in client.pubsub_service
- (xep-0060): extra dictionary can be used in bridge method for RSM and other options
- (xep-0060): XEP_0060.addManagedNode and XEP_0060.removeManagedNode allow to easily catch notifications for a specific node
- (xep-0060): retractItem manage "notify" attribute
- (xep-0060): new signal psEvent will be used to transmit notifications to frontends
- (xep-0060, constants): added a bunch of useful constants
- (xep-0163): removed personalEvent in favor of psEvent
- (xep-0163): addPEPEvent now filter non PEP events for in_callback
- (xep-0277): use of new XEP-0060 plugin's addManagedNode
- (xep-0277): fixed author handling for incoming blogs: author is the human readable name, author_jid it jid, and author_jid_verified is set to True is the jid is checked
- (xep-0277): reworked data2entry with Twisted instead of feed, item_id can now be specified, <content/> is changed to <title/> if there is only content
- (xep-0277): comments are now managed here (core removed from groupblog)
- (xep-0277): (comments) node is created if needed, default pubsub service is used if available, else PEP
- (xep-0277): retract is managed
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 16 Aug 2015 00:39:44 +0200 |
parents | 069ad98b360d |
children | d17772b0fe22 |
rev | line source |
---|---|
783 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT: a jabber client | |
1396 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
6 # Copyright (C) 2013, 2014, 2015 Adrien Cossa (souliane@mailoo.org) | |
783 | 7 |
8 # This program is free software: you can redistribute it and/or modify | |
9 # it under the terms of the GNU Affero General Public License as published by | |
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 | |
16 # GNU Affero General Public License for more details. | |
17 | |
18 # You should have received a copy of the GNU Affero General Public License | |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | |
21 """ Plugin chat states notification tests """ | |
22 | |
23 from constants import Const | |
24 from sat.test import helpers | |
915 | 25 from sat.core.constants import Const as C |
783 | 26 from sat.plugins import plugin_xep_0085 as plugin |
27 from copy import deepcopy | |
28 from twisted.internet import defer | |
29 from wokkel.generic import parseXml | |
30 | |
31 | |
32 class XEP_0085Test(helpers.SatTestCase): | |
33 | |
34 def setUp(self): | |
35 self.host = helpers.FakeSAT() | |
36 self.plugin = plugin.XEP_0085(self.host) | |
1278
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
37 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0]) |
783 | 38 |
39 def test_messageReceived(self): | |
40 for state in plugin.CHAT_STATES: | |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
41 xml = u""" |
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
42 <message type="chat" from="%s" to="%s" id="test_1"> |
783 | 43 %s |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
44 <%s xmlns='%s'/> |
783 | 45 </message> |
792
2136be5a44a8
test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
46 """ % (Const.JID_STR[1], |
2136be5a44a8
test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
47 Const.JID_STR[0], |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
48 "<body>test</body>" if state == "active" else "", |
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
49 state, plugin.NS_CHAT_STATES) |
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
50 stanza = parseXml(xml.encode("utf-8")) |
792
2136be5a44a8
test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
51 self.host.bridge.expectCall("chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0]) |
1278
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
52 self.plugin.messageReceivedTrigger(stanza, None, Const.PROFILE[0]) |
783 | 53 |
54 def test_sendMessageTrigger(self): | |
1278
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
55 def cb(data): |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
56 xml = data['xml'].toXml().encode("utf-8") |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
57 self.assertEqualXML(xml, expected.toXml().encode("utf-8")) |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
58 |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
59 d_list = [] |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
60 |
783 | 61 for state in plugin.CHAT_STATES: |
792
2136be5a44a8
test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
62 mess_data = {"to": Const.JID[0], |
783 | 63 "type": "chat", |
64 "message": "content", | |
65 "extra": {} if state == "active" else {"chat_state": state}} | |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
66 stanza = u""" |
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
67 <message type="chat" from="%s" to="%s" id="test_1"> |
783 | 68 %s |
69 </message> | |
792
2136be5a44a8
test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
70 """ % (Const.JID_STR[1], Const.JID_STR[0], |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
71 ("<body>%s</body>" % mess_data['message']) if state == "active" else "") |
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
783
diff
changeset
|
72 mess_data['xml'] = parseXml(stanza.encode("utf-8")) |
783 | 73 expected = deepcopy(mess_data['xml']) |
74 expected.addElement(state, plugin.NS_CHAT_STATES) | |
1278
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
75 post_treatments = defer.Deferred() |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
76 self.plugin.sendMessageTrigger(mess_data, None, post_treatments, Const.PROFILE[0]) |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
77 |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
78 post_treatments.addCallback(cb) |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
79 post_treatments.callback(mess_data) |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
80 d_list.append(post_treatments) |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
81 |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
82 def cb_list(dummy): # cancel the timer to not block the process |
1254
87fbe4640448
test: fixes test for XEP-0085 (use full JID)
souliane <souliane@mailoo.org>
parents:
924
diff
changeset
|
83 self.plugin.map[Const.PROFILE[0]][Const.JID[0]].timer.cancel() |
1278
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
84 |
347aee3a3f5c
test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
85 return defer.DeferredList(d_list).addCallback(cb_list) |