comparison src/test/test_plugin_xep_0313.py @ 1277:3a3e3014f9f8

plugin XEP-0313: first draft: - you can already test it with d-feet but it will bug unless you apply the changeset 60dfa2f5d61f which is waiting in the branch "frontends_multi_profiles" (actually just one "assert" to comment in plugin_xep_0085.py)
author souliane <souliane@mailoo.org>
date Fri, 19 Dec 2014 14:43:42 +0100
parents
children 41ffe2c2dddc
comparison
equal deleted inserted replaced
1276:56adf73bedeb 1277:3a3e3014f9f8
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
31
32 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
33
34
35 class XEP_0313Test(helpers.SatTestCase):
36
37 def setUp(self):
38 self.host = helpers.FakeSAT()
39 self.plugin = XEP_0313(self.host)
40
41 def test_queryArchive(self):
42 xml = """
43 <iq type='set' id='%s'>
44 <query xmlns='urn:xmpp:mam:0'/>
45 </iq>
46 """ % ("H_%d" % domish.Element._idCounter)
47 d = self.plugin.queryArchive(profile_key=C.PROFILE[0])
48 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
49 return d
50
51 def test_queryArchivePubsub(self):
52 xml = """
53 <iq type='set' id='%s'>
54 <query xmlns='urn:xmpp:mam:0' node='fdp/submitted/capulet.lit/sonnets' />
55 </iq>
56 """ % ("H_%d" % domish.Element._idCounter)
57 d = self.plugin.queryArchive(node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0])
58 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
59 return d
60
61 def test_queryArchiveWith(self):
62 xml = """
63 <iq type='set' id='%s'>
64 <query xmlns='urn:xmpp:mam:0'>
65 <x xmlns='jabber:x:data' type='submit'>
66 <field var='FORM_TYPE' type='hidden'>
67 <value>urn:xmpp:mam:0</value>
68 </field>
69 <field var='with' type='jid-single'>
70 <value>juliet@capulet.lit</value>
71 </field>
72 </x>
73 </query>
74 </iq>
75 """ % ("H_%d" % domish.Element._idCounter)
76 form = self.plugin.buildForm(with_jid=JID('juliet@capulet.lit'))
77 d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0])
78 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
79 return d
80
81 def test_queryArchiveStartEnd(self):
82 xml = """
83 <iq type='set' id='%s'>
84 <query xmlns='urn:xmpp:mam:0'>
85 <x xmlns='jabber:x:data' type='submit'>
86 <field var='FORM_TYPE' type='hidden'>
87 <value>urn:xmpp:mam:0</value>
88 </field>
89 <field var='start' type='text-single'>
90 <value>2010-06-07T00:00:00Z</value>
91 </field>
92 <field var='end' type='text-single'>
93 <value>2010-07-07T13:23:54Z</value>
94 </field>
95 </x>
96 </query>
97 </iq>
98 """ % ("H_%d" % domish.Element._idCounter)
99 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc())
100 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc())
101 form = self.plugin.buildForm(start=start, end=end)
102 d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0])
103 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
104 return d
105
106 def test_queryArchiveStart(self):
107 xml = """
108 <iq type='set' id='%s'>
109 <query xmlns='urn:xmpp:mam:0'>
110 <x xmlns='jabber:x:data' type='submit'>
111 <field var='FORM_TYPE' type='hidden'>
112 <value>urn:xmpp:mam:0</value>
113 </field>
114 <field var='start' type='text-single'>
115 <value>2010-08-07T00:00:00Z</value>
116 </field>
117 </x>
118 </query>
119 </iq>
120 """ % ("H_%d" % domish.Element._idCounter)
121 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
122 form = self.plugin.buildForm(start=start)
123 d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0])
124 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
125 return d
126
127 def test_queryArchiveRSM(self):
128 xml = """
129 <iq type='set' id='%s'>
130 <query xmlns='urn:xmpp:mam:0'>
131 <x xmlns='jabber:x:data' type='submit'>
132 <field var='FORM_TYPE' type='hidden'>
133 <value>urn:xmpp:mam:0</value>
134 </field>
135 <field var='start' type='text-single'>
136 <value>2010-08-07T00:00:00Z</value>
137 </field>
138 </x>
139 <set xmlns='http://jabber.org/protocol/rsm'>
140 <max>10</max>
141 </set>
142 </query>
143 </iq>
144 """ % ("H_%d" % domish.Element._idCounter)
145 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
146 form = self.plugin.buildForm(start=start)
147 rsm = RSMRequest(max=10)
148 d = self.plugin.queryArchive(form=form, rsm=rsm, profile_key=C.PROFILE[0])
149 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
150 return d
151
152 def test_queryArchiveRSMPaging(self):
153 xml = """
154 <iq type='set' id='%s'>
155 <query xmlns='urn:xmpp:mam:0'>
156 <x xmlns='jabber:x:data' type='submit'>
157 <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:0</value></field>
158 <field var='start' type='text-single'><value>2010-08-07T00:00:00Z</value></field>
159 </x>
160 <set xmlns='http://jabber.org/protocol/rsm'>
161 <max>10</max>
162 <after>09af3-cc343-b409f</after>
163 </set>
164 </query>
165 </iq>
166 """ % ("H_%d" % domish.Element._idCounter)
167 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
168 form = self.plugin.buildForm(start=start)
169 rsm = RSMRequest(max=10, after=u'09af3-cc343-b409f')
170 d = self.plugin.queryArchive(form=form, rsm=rsm, profile_key=C.PROFILE[0])
171 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
172 return d
173
174 def test_queryFields(self):
175 xml = """
176 <iq type='get' id="%s">
177 <query xmlns='urn:xmpp:mam:0'/>
178 </iq>
179 """ % ("H_%d" % domish.Element._idCounter)
180 d = self.plugin.queryFields(C.PROFILE[0])
181 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
182 return d
183
184 def test_queryArchiveFields(self):
185 xml = """
186 <iq type='set' id='%s'>
187 <query xmlns='urn:xmpp:mam:0'>
188 <x xmlns='jabber:x:data' type='submit'>
189 <field type='hidden' var='FORM_TYPE'>
190 <value>urn:xmpp:mam:0</value>
191 </field>
192 <field type='text-single' var='urn:example:xmpp:free-text-search'>
193 <value>Where arth thou, my Juliet?</value>
194 </field>
195 <field type='text-single' var='urn:example:xmpp:stanza-content'>
196 <value>{http://jabber.org/protocol/mood}mood/lonely</value>
197 </field>
198 </x>
199 </query>
200 </iq>
201 """ % ("H_%d" % domish.Element._idCounter)
202 extra = (('text-single', 'urn:example:xmpp:free-text-search',
203 'Where arth thou, my Juliet?'),
204 ('text-single', 'urn:example:xmpp:stanza-content',
205 '{http://jabber.org/protocol/mood}mood/lonely'))
206 form = self.plugin.buildForm(extra=extra)
207 d = self.plugin.queryArchive(form=form, profile_key=C.PROFILE[0])
208 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
209 return d
210
211 def test_queryPrefs(self):
212 xml = """
213 <iq type='get' id='%s'>
214 <prefs xmlns='urn:xmpp:mam:0'/>
215 </iq>
216 """ % ("H_%d" % domish.Element._idCounter)
217 d = self.plugin.queryPrefs(profile_key=C.PROFILE[0])
218 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
219 return d
220
221 def test_setPrefs(self):
222 xml = """
223 <iq type='set' id='%s'>
224 <prefs xmlns='urn:xmpp:mam:0' default='roster'>
225 <always>
226 <jid>romeo@montague.lit</jid>
227 </always>
228 <never>
229 <jid>montague@montague.lit</jid>
230 </never>
231 </prefs>
232 </iq>
233 """ % ("H_%d" % domish.Element._idCounter)
234 always = [JID('romeo@montague.lit')]
235 never = [JID('montague@montague.lit')]
236 d = self.plugin.setPrefs(always=always, never=never, profile_key=C.PROFILE[0])
237 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
238 return d