Mercurial > libervia-backend
annotate src/test/test_plugin_xep_0313.py @ 1422:be1fccf4854d
tmp (wokkel): licenses fixes:
the licenses headers were wrong, it was fixed: original work from Adrien Cossa is directly under AGPL v3 (with his agreement), work derivated from Wokkel is sublicensed to AGPL v3 as allowed by the original license, to stay consistent with the rest of the code base.
Theses files (and only these ones) can be relicensed again to fill Wokkel license if Ralph plan to merge them upstream...
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 23 Apr 2015 10:57:40 +0200 |
parents | 069ad98b360d |
children | 2d8fccec84e8 |
rev | line source |
---|---|
1277 | 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) | |
1277 | 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 dateutil.tz import tzutc | |
29 import datetime | |
1285
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1284
diff
changeset
|
30 |
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1284
diff
changeset
|
31 # TODO: change this when RSM and MAM are in wokkel |
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1284
diff
changeset
|
32 from sat.tmp.wokkel.rsm import RSMRequest |
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1284
diff
changeset
|
33 from sat.tmp.wokkel.mam import buildForm |
1277 | 34 |
35 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
36 SERVICE = 'sat-pubsub.tazar.int' |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
37 SERVICE_JID = JID(SERVICE) |
1277 | 38 |
39 | |
40 class XEP_0313Test(helpers.SatTestCase): | |
41 | |
42 def setUp(self): | |
43 self.host = helpers.FakeSAT() | |
44 self.plugin = XEP_0313(self.host) | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
45 client = self.plugin.getHandler(C.PROFILE[0]) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
46 client.makeConnection(self.host.getClient(C.PROFILE[0]).xmlstream) |
1277 | 47 |
48 def test_queryArchive(self): | |
49 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
50 <iq type='set' id='%s' to='%s'> |
1277 | 51 <query xmlns='urn:xmpp:mam:0'/> |
52 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
53 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
54 d = self.plugin.queryArchive(SERVICE_JID, profile_key=C.PROFILE[0]) |
1277 | 55 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
56 return d | |
57 | |
58 def test_queryArchivePubsub(self): | |
59 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
60 <iq type='set' id='%s' to='%s'> |
1277 | 61 <query xmlns='urn:xmpp:mam:0' node='fdp/submitted/capulet.lit/sonnets' /> |
62 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
63 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
64 d = self.plugin.queryArchive(SERVICE_JID, node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0]) |
1277 | 65 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
66 return d | |
67 | |
68 def test_queryArchiveWith(self): | |
69 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
70 <iq type='set' id='%s' to='%s'> |
1277 | 71 <query xmlns='urn:xmpp:mam:0'> |
72 <x xmlns='jabber:x:data' type='submit'> | |
73 <field var='FORM_TYPE' type='hidden'> | |
74 <value>urn:xmpp:mam:0</value> | |
75 </field> | |
76 <field var='with' type='jid-single'> | |
77 <value>juliet@capulet.lit</value> | |
78 </field> | |
79 </x> | |
80 </query> | |
81 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
82 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
83 form = buildForm(with_jid=JID('juliet@capulet.lit')) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
84 d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0]) |
1277 | 85 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
86 return d | |
87 | |
88 def test_queryArchiveStartEnd(self): | |
89 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
90 <iq type='set' id='%s' to='%s'> |
1277 | 91 <query xmlns='urn:xmpp:mam:0'> |
92 <x xmlns='jabber:x:data' type='submit'> | |
93 <field var='FORM_TYPE' type='hidden'> | |
94 <value>urn:xmpp:mam:0</value> | |
95 </field> | |
96 <field var='start' type='text-single'> | |
97 <value>2010-06-07T00:00:00Z</value> | |
98 </field> | |
99 <field var='end' type='text-single'> | |
100 <value>2010-07-07T13:23:54Z</value> | |
101 </field> | |
102 </x> | |
103 </query> | |
104 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
105 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 106 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc()) |
107 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc()) | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
108 form = buildForm(start=start, end=end) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
109 d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0]) |
1277 | 110 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
111 return d | |
112 | |
113 def test_queryArchiveStart(self): | |
114 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
115 <iq type='set' id='%s' to='%s'> |
1277 | 116 <query xmlns='urn:xmpp:mam:0'> |
117 <x xmlns='jabber:x:data' type='submit'> | |
118 <field var='FORM_TYPE' type='hidden'> | |
119 <value>urn:xmpp:mam:0</value> | |
120 </field> | |
121 <field var='start' type='text-single'> | |
122 <value>2010-08-07T00:00:00Z</value> | |
123 </field> | |
124 </x> | |
125 </query> | |
126 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
127 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 128 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
129 form = buildForm(start=start) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
130 d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0]) |
1277 | 131 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
132 return d | |
133 | |
134 def test_queryArchiveRSM(self): | |
135 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
136 <iq type='set' id='%s' to='%s'> |
1277 | 137 <query xmlns='urn:xmpp:mam:0'> |
138 <x xmlns='jabber:x:data' type='submit'> | |
139 <field var='FORM_TYPE' type='hidden'> | |
140 <value>urn:xmpp:mam:0</value> | |
141 </field> | |
142 <field var='start' type='text-single'> | |
143 <value>2010-08-07T00:00:00Z</value> | |
144 </field> | |
145 </x> | |
146 <set xmlns='http://jabber.org/protocol/rsm'> | |
147 <max>10</max> | |
148 </set> | |
149 </query> | |
150 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
151 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 152 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
153 form = buildForm(start=start) |
1277 | 154 rsm = RSMRequest(max=10) |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
155 d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0]) |
1277 | 156 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
157 return d | |
158 | |
159 def test_queryArchiveRSMPaging(self): | |
160 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
161 <iq type='set' id='%s' to='%s'> |
1277 | 162 <query xmlns='urn:xmpp:mam:0'> |
163 <x xmlns='jabber:x:data' type='submit'> | |
164 <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:0</value></field> | |
165 <field var='start' type='text-single'><value>2010-08-07T00:00:00Z</value></field> | |
166 </x> | |
167 <set xmlns='http://jabber.org/protocol/rsm'> | |
168 <max>10</max> | |
169 <after>09af3-cc343-b409f</after> | |
170 </set> | |
171 </query> | |
172 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
173 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 174 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
175 form = buildForm(start=start) |
1277 | 176 rsm = RSMRequest(max=10, after=u'09af3-cc343-b409f') |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
177 d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0]) |
1277 | 178 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
179 return d | |
180 | |
181 def test_queryFields(self): | |
182 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
183 <iq type='get' id="%s" to='%s'> |
1277 | 184 <query xmlns='urn:xmpp:mam:0'/> |
185 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
186 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
187 d = self.plugin.queryFields(SERVICE_JID, C.PROFILE[0]) |
1277 | 188 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
189 return d | |
190 | |
191 def test_queryArchiveFields(self): | |
192 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
193 <iq type='set' id='%s' to='%s'> |
1277 | 194 <query xmlns='urn:xmpp:mam:0'> |
195 <x xmlns='jabber:x:data' type='submit'> | |
196 <field type='hidden' var='FORM_TYPE'> | |
197 <value>urn:xmpp:mam:0</value> | |
198 </field> | |
199 <field type='text-single' var='urn:example:xmpp:free-text-search'> | |
200 <value>Where arth thou, my Juliet?</value> | |
201 </field> | |
202 <field type='text-single' var='urn:example:xmpp:stanza-content'> | |
203 <value>{http://jabber.org/protocol/mood}mood/lonely</value> | |
204 </field> | |
205 </x> | |
206 </query> | |
207 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
208 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
209 extra = [{'fieldType': 'text-single', |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
210 'var': 'urn:example:xmpp:free-text-search', |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
211 'value': 'Where arth thou, my Juliet?'}, |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
212 {'fieldType': 'text-single', |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
213 'var': 'urn:example:xmpp:stanza-content', |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
214 'value': '{http://jabber.org/protocol/mood}mood/lonely'}] |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
215 form = buildForm(extra=extra) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
216 d = self.plugin.queryArchive(SERVICE_JID, form=form, profile_key=C.PROFILE[0]) |
1277 | 217 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
218 return d | |
219 | |
220 def test_queryPrefs(self): | |
221 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
222 <iq type='get' id='%s' to='%s'> |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
223 <prefs xmlns='urn:xmpp:mam:0'> |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
224 <always/> |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
225 <never/> |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
226 </prefs> |
1277 | 227 </iq> |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
228 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
229 d = self.plugin.getPrefs(SERVICE_JID, profile_key=C.PROFILE[0]) |
1277 | 230 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
231 return d | |
232 | |
233 def test_setPrefs(self): | |
234 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
235 <iq type='set' id='%s' to='%s'> |
1277 | 236 <prefs xmlns='urn:xmpp:mam:0' default='roster'> |
237 <always> | |
238 <jid>romeo@montague.lit</jid> | |
239 </always> | |
240 <never> | |
241 <jid>montague@montague.lit</jid> | |
242 </never> | |
243 </prefs> | |
244 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
245 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 246 always = [JID('romeo@montague.lit')] |
247 never = [JID('montague@montague.lit')] | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
248 d = self.plugin.setPrefs(SERVICE_JID, always=always, never=never, profile_key=C.PROFILE[0]) |
1277 | 249 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
250 return d |