Mercurial > libervia-backend
annotate sat/test/test_plugin_xep_0334.py @ 2565:ea106dfa2145
setup, constant: use https address in APP_URL, and keep pypi NAME separated from constants
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Apr 2018 09:04:55 +0200 |
parents | 26edcf3a30eb |
children | 56f94936df1e |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1279 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # SAT: a jabber client | |
2483 | 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
1766 | 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) |
1279 | 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 XEP-0334 """ | |
22 | |
23 from constants import Const as C | |
24 from sat.test import helpers | |
25 from sat.plugins.plugin_xep_0334 import XEP_0334 | |
26 from twisted.internet import defer | |
27 from wokkel.generic import parseXml | |
28 from sat.core import exceptions | |
29 | |
30 HINTS = ('no-permanent-storage', 'no-storage', 'no-copy') | |
31 | |
32 | |
33 class XEP_0334Test(helpers.SatTestCase): | |
34 | |
35 def setUp(self): | |
36 self.host = helpers.FakeSAT() | |
37 self.plugin = XEP_0334(self.host) | |
38 | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
39 def test_messageSendTrigger(self): |
1279 | 40 template_xml = """ |
41 <message | |
42 from='romeo@montague.net/orchard' | |
43 to='juliet@capulet.com' | |
44 type='chat'> | |
45 <body>text</body> | |
46 %s | |
47 </message> | |
48 """ | |
49 original_xml = template_xml % '' | |
50 | |
51 d_list = [] | |
52 | |
53 def cb(data, expected_xml): | |
54 result_xml = data['xml'].toXml().encode("utf-8") | |
55 self.assertEqualXML(result_xml, expected_xml, True) | |
56 | |
57 for key in (HINTS + ('', 'dummy_hint')): | |
58 mess_data = {'xml': parseXml(original_xml.encode("utf-8")), | |
59 'extra': {key: True} | |
60 } | |
61 treatments = defer.Deferred() | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
62 self.plugin.messageSendTrigger(self.host.getClient(C.PROFILE[0]), mess_data, defer.Deferred(), treatments) |
1279 | 63 if treatments.callbacks: # the trigger added a callback |
64 expected_xml = template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key) | |
65 treatments.addCallback(cb, expected_xml) | |
66 treatments.callback(mess_data) | |
67 d_list.append(treatments) | |
68 | |
69 return defer.DeferredList(d_list) | |
70 | |
71 def test_messageReceivedTrigger(self): | |
72 template_xml = """ | |
73 <message | |
74 from='romeo@montague.net/orchard' | |
75 to='juliet@capulet.com' | |
76 type='chat'> | |
77 <body>text</body> | |
78 %s | |
79 </message> | |
80 """ | |
81 | |
82 def cb(dummy): | |
83 raise Exception("Errback should not be ran instead of callback!") | |
84 | |
85 def eb(failure): | |
86 failure.trap(exceptions.SkipHistory) | |
87 | |
88 d_list = [] | |
89 | |
90 for key in (HINTS + ('dummy_hint',)): | |
91 message = parseXml(template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key)) | |
92 post_treat = defer.Deferred() | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
93 self.plugin.messageReceivedTrigger(self.host.getClient(C.PROFILE[0]), message, post_treat) |
1279 | 94 if post_treat.callbacks: |
95 assert(key in ('no-permanent-storage', 'no-storage')) | |
96 post_treat.addCallbacks(cb, eb) | |
97 post_treat.callback(None) | |
98 d_list.append(post_treat) | |
99 else: | |
100 assert(key not in ('no-permanent-storage', 'no-storage')) | |
101 | |
102 return defer.DeferredList(d_list) |