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