Mercurial > libervia-backend
comparison sat/test/test_plugin_xep_0085.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | src/test/test_plugin_xep_0085.py@0046283a285d |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT: a jabber client | |
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) | |
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) | |
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 | |
25 from sat.core.constants import Const as C | |
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) | |
37 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0]) | |
38 | |
39 def test_messageReceived(self): | |
40 for state in plugin.CHAT_STATES: | |
41 xml = u""" | |
42 <message type="chat" from="%s" to="%s" id="test_1"> | |
43 %s | |
44 <%s xmlns='%s'/> | |
45 </message> | |
46 """ % (Const.JID_STR[1], | |
47 Const.JID_STR[0], | |
48 "<body>test</body>" if state == "active" else "", | |
49 state, plugin.NS_CHAT_STATES) | |
50 stanza = parseXml(xml.encode("utf-8")) | |
51 self.host.bridge.expectCall("chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0]) | |
52 self.plugin.messageReceivedTrigger(self.host.getClient(Const.PROFILE[0]), stanza, None) | |
53 | |
54 def test_messageSendTrigger(self): | |
55 def cb(data): | |
56 xml = data['xml'].toXml().encode("utf-8") | |
57 self.assertEqualXML(xml, expected.toXml().encode("utf-8")) | |
58 | |
59 d_list = [] | |
60 | |
61 for state in plugin.CHAT_STATES: | |
62 mess_data = {"to": Const.JID[0], | |
63 "type": "chat", | |
64 "message": "content", | |
65 "extra": {} if state == "active" else {"chat_state": state}} | |
66 stanza = u""" | |
67 <message type="chat" from="%s" to="%s" id="test_1"> | |
68 %s | |
69 </message> | |
70 """ % (Const.JID_STR[1], Const.JID_STR[0], | |
71 ("<body>%s</body>" % mess_data['message']) if state == "active" else "") | |
72 mess_data['xml'] = parseXml(stanza.encode("utf-8")) | |
73 expected = deepcopy(mess_data['xml']) | |
74 expected.addElement(state, plugin.NS_CHAT_STATES) | |
75 post_treatments = defer.Deferred() | |
76 self.plugin.messageSendTrigger(self.host.getClient(Const.PROFILE[0]), mess_data, None, post_treatments) | |
77 | |
78 post_treatments.addCallback(cb) | |
79 post_treatments.callback(mess_data) | |
80 d_list.append(post_treatments) | |
81 | |
82 def cb_list(dummy): # cancel the timer to not block the process | |
83 self.plugin.map[Const.PROFILE[0]][Const.JID[0]].timer.cancel() | |
84 | |
85 return defer.DeferredList(d_list).addCallback(cb_list) |