comparison sat/test/test_plugin_xep_0334.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_0334.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 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
39 def test_messageSendTrigger(self):
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()
62 self.plugin.messageSendTrigger(self.host.getClient(C.PROFILE[0]), mess_data, defer.Deferred(), treatments)
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()
93 self.plugin.messageReceivedTrigger(self.host.getClient(C.PROFILE[0]), message, post_treat)
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)