Mercurial > libervia-backend
annotate src/test/test_plugin_xep_0313.py @ 2498:d6de69da3dd4
core (client): component improvments:
- renamed component boolean to is_component for more clarity
- profileConnected/profileDisconnected don't use a suffix anymore, it's called for both client and component.
To check for there, the is_component boolean is enough
- fixed dependencies handling
- componentStart is not mandatory anymore, as a component can just be used with its handler
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Feb 2018 18:28:39 +0100 |
parents | 0046283a285d |
children |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1910
diff
changeset
|
1 #!/usr/bin/env python2 |
1277 | 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) |
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 | |
1910 | 28 from wokkel.data_form import Field |
1277 | 29 from dateutil.tz import tzutc |
30 import datetime | |
1285
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1284
diff
changeset
|
31 |
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1284
diff
changeset
|
32 # TODO: change this when RSM and MAM are in wokkel |
2413
70399d1acb47
tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
33 from sat_tmp.wokkel.rsm import RSMRequest |
70399d1acb47
tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
34 from sat_tmp.wokkel.mam import buildForm, MAMRequest |
1277 | 35 |
36 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
37 SERVICE = 'sat-pubsub.tazar.int' |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
38 SERVICE_JID = JID(SERVICE) |
1277 | 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) | |
1910 | 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) | |
1277 | 49 |
50 def test_queryArchive(self): | |
51 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
52 <iq type='set' id='%s' to='%s'> |
1910 | 53 <query xmlns='urn:xmpp:mam:1'/> |
1277 | 54 </iq> |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
55 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1910 | 56 d = self.plugin.queryArchive(self.client, MAMRequest(), SERVICE_JID) |
1277 | 57 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
58 return d | |
59 | |
60 def test_queryArchivePubsub(self): | |
61 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
62 <iq type='set' id='%s' to='%s'> |
1910 | 63 <query xmlns='urn:xmpp:mam:1' node='fdp/submitted/capulet.lit/sonnets' /> |
1277 | 64 </iq> |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
65 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1910 | 66 d = self.plugin.queryArchive(self.client, MAMRequest(node="fdp/submitted/capulet.lit/sonnets"), SERVICE_JID) |
1277 | 67 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
68 return d | |
69 | |
70 def test_queryArchiveWith(self): | |
71 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
72 <iq type='set' id='%s' to='%s'> |
1910 | 73 <query xmlns='urn:xmpp:mam:1'> |
1277 | 74 <x xmlns='jabber:x:data' type='submit'> |
75 <field var='FORM_TYPE' type='hidden'> | |
1910 | 76 <value>urn:xmpp:mam:1</value> |
1277 | 77 </field> |
78 <field var='with' type='jid-single'> | |
79 <value>juliet@capulet.lit</value> | |
80 </field> | |
81 </x> | |
82 </query> | |
83 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
84 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
85 form = buildForm(with_jid=JID('juliet@capulet.lit')) |
1910 | 86 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) |
1277 | 87 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
88 return d | |
89 | |
90 def test_queryArchiveStartEnd(self): | |
91 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
92 <iq type='set' id='%s' to='%s'> |
1910 | 93 <query xmlns='urn:xmpp:mam:1'> |
1277 | 94 <x xmlns='jabber:x:data' type='submit'> |
95 <field var='FORM_TYPE' type='hidden'> | |
1910 | 96 <value>urn:xmpp:mam:1</value> |
1277 | 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> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
107 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 108 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc()) |
109 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
|
110 form = buildForm(start=start, end=end) |
1910 | 111 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) |
1277 | 112 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
113 return d | |
114 | |
115 def test_queryArchiveStart(self): | |
116 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
117 <iq type='set' id='%s' to='%s'> |
1910 | 118 <query xmlns='urn:xmpp:mam:1'> |
1277 | 119 <x xmlns='jabber:x:data' type='submit'> |
120 <field var='FORM_TYPE' type='hidden'> | |
1910 | 121 <value>urn:xmpp:mam:1</value> |
1277 | 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> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
129 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 130 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
|
131 form = buildForm(start=start) |
1910 | 132 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) |
1277 | 133 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
134 return d | |
135 | |
136 def test_queryArchiveRSM(self): | |
137 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
138 <iq type='set' id='%s' to='%s'> |
1910 | 139 <query xmlns='urn:xmpp:mam:1'> |
1277 | 140 <x xmlns='jabber:x:data' type='submit'> |
141 <field var='FORM_TYPE' type='hidden'> | |
1910 | 142 <value>urn:xmpp:mam:1</value> |
1277 | 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> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
153 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 154 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
|
155 form = buildForm(start=start) |
1424 | 156 rsm = RSMRequest(max_=10) |
1910 | 157 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID) |
1277 | 158 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
159 return d | |
160 | |
161 def test_queryArchiveRSMPaging(self): | |
162 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
163 <iq type='set' id='%s' to='%s'> |
1910 | 164 <query xmlns='urn:xmpp:mam:1'> |
1277 | 165 <x xmlns='jabber:x:data' type='submit'> |
1910 | 166 <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:1</value></field> |
1277 | 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> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
175 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 176 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
|
177 form = buildForm(start=start) |
1424 | 178 rsm = RSMRequest(max_=10, after=u'09af3-cc343-b409f') |
1910 | 179 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID) |
1277 | 180 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
181 return d | |
182 | |
183 def test_queryFields(self): | |
184 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
185 <iq type='get' id="%s" to='%s'> |
1910 | 186 <query xmlns='urn:xmpp:mam:1'/> |
1277 | 187 </iq> |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
188 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1910 | 189 d = self.plugin.queryFields(self.client, SERVICE_JID) |
1277 | 190 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
191 return d | |
192 | |
193 def test_queryArchiveFields(self): | |
194 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
195 <iq type='set' id='%s' to='%s'> |
1910 | 196 <query xmlns='urn:xmpp:mam:1'> |
1277 | 197 <x xmlns='jabber:x:data' type='submit'> |
198 <field type='hidden' var='FORM_TYPE'> | |
1910 | 199 <value>urn:xmpp:mam:1</value> |
1277 | 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> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
210 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1910 | 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) | |
1277 | 216 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
217 return d | |
218 | |
219 def test_queryPrefs(self): | |
220 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
221 <iq type='get' id='%s' to='%s'> |
1910 | 222 <prefs xmlns='urn:xmpp:mam:1'> |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
223 <always/> |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
224 <never/> |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
225 </prefs> |
1277 | 226 </iq> |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
227 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1910 | 228 d = self.plugin.getPrefs(self.client, SERVICE_JID) |
1277 | 229 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
230 return d | |
231 | |
232 def test_setPrefs(self): | |
233 xml = """ | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
234 <iq type='set' id='%s' to='%s'> |
1910 | 235 <prefs xmlns='urn:xmpp:mam:1' default='roster'> |
1277 | 236 <always> |
237 <jid>romeo@montague.lit</jid> | |
238 </always> | |
239 <never> | |
240 <jid>montague@montague.lit</jid> | |
241 </never> | |
242 </prefs> | |
243 </iq> | |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
244 """ % (("H_%d" % domish.Element._idCounter), SERVICE) |
1277 | 245 always = [JID('romeo@montague.lit')] |
246 never = [JID('montague@montague.lit')] | |
1910 | 247 d = self.plugin.setPrefs(self.client, SERVICE_JID, always=always, never=never) |
1277 | 248 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) |
249 return d |