Mercurial > libervia-backend
comparison sat/test/test_plugin_xep_0313.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_0313.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-0313 """ | |
22 | |
23 from constants import Const as C | |
24 from sat.test import helpers | |
25 from sat.plugins.plugin_xep_0313 import XEP_0313 | |
26 from twisted.words.protocols.jabber.jid import JID | |
27 from twisted.words.xish import domish | |
28 from wokkel.data_form import Field | |
29 from dateutil.tz import tzutc | |
30 import datetime | |
31 | |
32 # TODO: change this when RSM and MAM are in wokkel | |
33 from sat_tmp.wokkel.rsm import RSMRequest | |
34 from sat_tmp.wokkel.mam import buildForm, MAMRequest | |
35 | |
36 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | |
37 SERVICE = 'sat-pubsub.tazar.int' | |
38 SERVICE_JID = JID(SERVICE) | |
39 | |
40 | |
41 class XEP_0313Test(helpers.SatTestCase): | |
42 | |
43 def setUp(self): | |
44 self.host = helpers.FakeSAT() | |
45 self.plugin = XEP_0313(self.host) | |
46 self.client = self.host.getClient(C.PROFILE[0]) | |
47 mam_client = self.plugin.getHandler(C.PROFILE[0]) | |
48 mam_client.makeConnection(self.host.getClient(C.PROFILE[0]).xmlstream) | |
49 | |
50 def test_queryArchive(self): | |
51 xml = """ | |
52 <iq type='set' id='%s' to='%s'> | |
53 <query xmlns='urn:xmpp:mam:1'/> | |
54 </iq> | |
55 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
56 d = self.plugin.queryArchive(self.client, MAMRequest(), SERVICE_JID) | |
57 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
58 return d | |
59 | |
60 def test_queryArchivePubsub(self): | |
61 xml = """ | |
62 <iq type='set' id='%s' to='%s'> | |
63 <query xmlns='urn:xmpp:mam:1' node='fdp/submitted/capulet.lit/sonnets' /> | |
64 </iq> | |
65 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
66 d = self.plugin.queryArchive(self.client, MAMRequest(node="fdp/submitted/capulet.lit/sonnets"), SERVICE_JID) | |
67 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
68 return d | |
69 | |
70 def test_queryArchiveWith(self): | |
71 xml = """ | |
72 <iq type='set' id='%s' to='%s'> | |
73 <query xmlns='urn:xmpp:mam:1'> | |
74 <x xmlns='jabber:x:data' type='submit'> | |
75 <field var='FORM_TYPE' type='hidden'> | |
76 <value>urn:xmpp:mam:1</value> | |
77 </field> | |
78 <field var='with' type='jid-single'> | |
79 <value>juliet@capulet.lit</value> | |
80 </field> | |
81 </x> | |
82 </query> | |
83 </iq> | |
84 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
85 form = buildForm(with_jid=JID('juliet@capulet.lit')) | |
86 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) | |
87 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
88 return d | |
89 | |
90 def test_queryArchiveStartEnd(self): | |
91 xml = """ | |
92 <iq type='set' id='%s' to='%s'> | |
93 <query xmlns='urn:xmpp:mam:1'> | |
94 <x xmlns='jabber:x:data' type='submit'> | |
95 <field var='FORM_TYPE' type='hidden'> | |
96 <value>urn:xmpp:mam:1</value> | |
97 </field> | |
98 <field var='start' type='text-single'> | |
99 <value>2010-06-07T00:00:00Z</value> | |
100 </field> | |
101 <field var='end' type='text-single'> | |
102 <value>2010-07-07T13:23:54Z</value> | |
103 </field> | |
104 </x> | |
105 </query> | |
106 </iq> | |
107 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
108 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc()) | |
109 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc()) | |
110 form = buildForm(start=start, end=end) | |
111 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) | |
112 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
113 return d | |
114 | |
115 def test_queryArchiveStart(self): | |
116 xml = """ | |
117 <iq type='set' id='%s' to='%s'> | |
118 <query xmlns='urn:xmpp:mam:1'> | |
119 <x xmlns='jabber:x:data' type='submit'> | |
120 <field var='FORM_TYPE' type='hidden'> | |
121 <value>urn:xmpp:mam:1</value> | |
122 </field> | |
123 <field var='start' type='text-single'> | |
124 <value>2010-08-07T00:00:00Z</value> | |
125 </field> | |
126 </x> | |
127 </query> | |
128 </iq> | |
129 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
130 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) | |
131 form = buildForm(start=start) | |
132 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) | |
133 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
134 return d | |
135 | |
136 def test_queryArchiveRSM(self): | |
137 xml = """ | |
138 <iq type='set' id='%s' to='%s'> | |
139 <query xmlns='urn:xmpp:mam:1'> | |
140 <x xmlns='jabber:x:data' type='submit'> | |
141 <field var='FORM_TYPE' type='hidden'> | |
142 <value>urn:xmpp:mam:1</value> | |
143 </field> | |
144 <field var='start' type='text-single'> | |
145 <value>2010-08-07T00:00:00Z</value> | |
146 </field> | |
147 </x> | |
148 <set xmlns='http://jabber.org/protocol/rsm'> | |
149 <max>10</max> | |
150 </set> | |
151 </query> | |
152 </iq> | |
153 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
154 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) | |
155 form = buildForm(start=start) | |
156 rsm = RSMRequest(max_=10) | |
157 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID) | |
158 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
159 return d | |
160 | |
161 def test_queryArchiveRSMPaging(self): | |
162 xml = """ | |
163 <iq type='set' id='%s' to='%s'> | |
164 <query xmlns='urn:xmpp:mam:1'> | |
165 <x xmlns='jabber:x:data' type='submit'> | |
166 <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:1</value></field> | |
167 <field var='start' type='text-single'><value>2010-08-07T00:00:00Z</value></field> | |
168 </x> | |
169 <set xmlns='http://jabber.org/protocol/rsm'> | |
170 <max>10</max> | |
171 <after>09af3-cc343-b409f</after> | |
172 </set> | |
173 </query> | |
174 </iq> | |
175 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
176 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) | |
177 form = buildForm(start=start) | |
178 rsm = RSMRequest(max_=10, after=u'09af3-cc343-b409f') | |
179 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID) | |
180 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
181 return d | |
182 | |
183 def test_queryFields(self): | |
184 xml = """ | |
185 <iq type='get' id="%s" to='%s'> | |
186 <query xmlns='urn:xmpp:mam:1'/> | |
187 </iq> | |
188 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
189 d = self.plugin.queryFields(self.client, SERVICE_JID) | |
190 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
191 return d | |
192 | |
193 def test_queryArchiveFields(self): | |
194 xml = """ | |
195 <iq type='set' id='%s' to='%s'> | |
196 <query xmlns='urn:xmpp:mam:1'> | |
197 <x xmlns='jabber:x:data' type='submit'> | |
198 <field type='hidden' var='FORM_TYPE'> | |
199 <value>urn:xmpp:mam:1</value> | |
200 </field> | |
201 <field type='text-single' var='urn:example:xmpp:free-text-search'> | |
202 <value>Where arth thou, my Juliet?</value> | |
203 </field> | |
204 <field type='text-single' var='urn:example:xmpp:stanza-content'> | |
205 <value>{http://jabber.org/protocol/mood}mood/lonely</value> | |
206 </field> | |
207 </x> | |
208 </query> | |
209 </iq> | |
210 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
211 extra_fields = [Field('text-single', 'urn:example:xmpp:free-text-search', 'Where arth thou, my Juliet?'), | |
212 Field('text-single', 'urn:example:xmpp:stanza-content', '{http://jabber.org/protocol/mood}mood/lonely') | |
213 ] | |
214 form = buildForm(extra_fields=extra_fields) | |
215 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) | |
216 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
217 return d | |
218 | |
219 def test_queryPrefs(self): | |
220 xml = """ | |
221 <iq type='get' id='%s' to='%s'> | |
222 <prefs xmlns='urn:xmpp:mam:1'> | |
223 <always/> | |
224 <never/> | |
225 </prefs> | |
226 </iq> | |
227 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
228 d = self.plugin.getPrefs(self.client, SERVICE_JID) | |
229 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
230 return d | |
231 | |
232 def test_setPrefs(self): | |
233 xml = """ | |
234 <iq type='set' id='%s' to='%s'> | |
235 <prefs xmlns='urn:xmpp:mam:1' default='roster'> | |
236 <always> | |
237 <jid>romeo@montague.lit</jid> | |
238 </always> | |
239 <never> | |
240 <jid>montague@montague.lit</jid> | |
241 </never> | |
242 </prefs> | |
243 </iq> | |
244 """ % (("H_%d" % domish.Element._idCounter), SERVICE) | |
245 always = [JID('romeo@montague.lit')] | |
246 never = [JID('montague@montague.lit')] | |
247 d = self.plugin.setPrefs(self.client, SERVICE_JID, always=always, never=never) | |
248 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) | |
249 return d |