Mercurial > libervia-backend
comparison sat/test/test_plugin_misc_groupblog.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_misc_groupblog.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 groupblogs """ | |
22 | |
23 from constants import Const as C | |
24 from sat.test import helpers, helpers_plugins | |
25 from sat.plugins import plugin_misc_groupblog | |
26 from sat.plugins import plugin_xep_0060 | |
27 from sat.plugins import plugin_xep_0277 | |
28 from sat.plugins import plugin_xep_0163 | |
29 from sat.plugins import plugin_misc_text_syntaxes | |
30 from twisted.internet import defer | |
31 from twisted.words.protocols.jabber import jid | |
32 | |
33 | |
34 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | |
35 | |
36 DO_NOT_COUNT_COMMENTS = -1 | |
37 | |
38 SERVICE = u'pubsub.example.com' | |
39 PUBLISHER = u'test@example.org' | |
40 OTHER_PUBLISHER = u'other@xmpp.net' | |
41 NODE_ID = u'urn:xmpp:groupblog:{publisher}'.format(publisher=PUBLISHER) | |
42 OTHER_NODE_ID = u'urn:xmpp:groupblog:{publisher}'.format(publisher=OTHER_PUBLISHER) | |
43 ITEM_ID_1 = u'c745a688-9b02-11e3-a1a3-c0143dd4fe51' | |
44 COMMENT_ID_1 = u'd745a688-9b02-11e3-a1a3-c0143dd4fe52' | |
45 COMMENT_ID_2 = u'e745a688-9b02-11e3-a1a3-c0143dd4fe53' | |
46 | |
47 | |
48 def COMMENTS_NODE_ID(publisher=PUBLISHER): | |
49 return u'urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}'.format(id=ITEM_ID_1, publisher=publisher) | |
50 | |
51 | |
52 def COMMENTS_NODE_URL(publisher=PUBLISHER): | |
53 return u'xmpp:{service}?node={node}'.format(service=SERVICE, id=ITEM_ID_1, | |
54 node=COMMENTS_NODE_ID(publisher).replace(':', '%3A').replace('@', '%40')) | |
55 | |
56 | |
57 def ITEM(publisher=PUBLISHER): | |
58 return u""" | |
59 <item id='{id}' xmlns='{ns}'> | |
60 <entry> | |
61 <title type='text'>The Uses of This World</title> | |
62 <id>{id}</id> | |
63 <updated>2003-12-12T17:47:23Z</updated> | |
64 <published>2003-12-12T17:47:23Z</published> | |
65 <link href='{comments_node_url}' rel='replies' title='comments'/> | |
66 <author> | |
67 <name>{publisher}</name> | |
68 </author> | |
69 </entry> | |
70 </item> | |
71 """.format(ns=NS_PUBSUB, id=ITEM_ID_1, publisher=publisher, comments_node_url=COMMENTS_NODE_URL(publisher)) | |
72 | |
73 | |
74 def COMMENT(id_=COMMENT_ID_1): | |
75 return u""" | |
76 <item id='{id}' xmlns='{ns}'> | |
77 <entry> | |
78 <title type='text'>The Uses of This World</title> | |
79 <id>{id}</id> | |
80 <updated>2003-12-12T17:47:23Z</updated> | |
81 <published>2003-12-12T17:47:23Z</published> | |
82 <author> | |
83 <name>{publisher}</name> | |
84 </author> | |
85 </entry> | |
86 </item> | |
87 """.format(ns=NS_PUBSUB, id=id_, publisher=PUBLISHER) | |
88 | |
89 | |
90 def ITEM_DATA(id_=ITEM_ID_1, count=0): | |
91 res = {'id': ITEM_ID_1, | |
92 'type': 'main_item', | |
93 'content': 'The Uses of This World', | |
94 'author': PUBLISHER, | |
95 'updated': '1071251243.0', | |
96 'published': '1071251243.0', | |
97 'service': SERVICE, | |
98 'comments': COMMENTS_NODE_URL_1, | |
99 'comments_service': SERVICE, | |
100 'comments_node': COMMENTS_NODE_ID_1} | |
101 if count != DO_NOT_COUNT_COMMENTS: | |
102 res.update({'comments_count': unicode(count)}) | |
103 return res | |
104 | |
105 | |
106 def COMMENT_DATA(id_=COMMENT_ID_1): | |
107 return {'id': id_, | |
108 'type': 'comment', | |
109 'content': 'The Uses of This World', | |
110 'author': PUBLISHER, | |
111 'updated': '1071251243.0', | |
112 'published': '1071251243.0', | |
113 'service': SERVICE, | |
114 'node': COMMENTS_NODE_ID_1, | |
115 'verified_publisher': 'false'} | |
116 | |
117 | |
118 COMMENTS_NODE_ID_1 = COMMENTS_NODE_ID() | |
119 COMMENTS_NODE_ID_2 = COMMENTS_NODE_ID(OTHER_PUBLISHER) | |
120 COMMENTS_NODE_URL_1 = COMMENTS_NODE_URL() | |
121 COMMENTS_NODE_URL_2 = COMMENTS_NODE_URL(OTHER_PUBLISHER) | |
122 ITEM_1 = ITEM() | |
123 ITEM_2 = ITEM(OTHER_PUBLISHER) | |
124 COMMENT_1 = COMMENT(COMMENT_ID_1) | |
125 COMMENT_2 = COMMENT(COMMENT_ID_2) | |
126 | |
127 | |
128 def ITEM_DATA_1(count=0): | |
129 return ITEM_DATA(count=count) | |
130 | |
131 COMMENT_DATA_1 = COMMENT_DATA() | |
132 COMMENT_DATA_2 = COMMENT_DATA(COMMENT_ID_2) | |
133 | |
134 | |
135 class XEP_groupblogTest(helpers.SatTestCase): | |
136 | |
137 def setUp(self): | |
138 self.host = helpers.FakeSAT() | |
139 self.host.plugins['XEP-0060'] = plugin_xep_0060.XEP_0060(self.host) | |
140 self.host.plugins['XEP-0163'] = plugin_xep_0163.XEP_0163(self.host) | |
141 reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error | |
142 self.host.plugins['TEXT-SYNTAXES'] = plugin_misc_text_syntaxes.TextSyntaxes(self.host) | |
143 self.host.plugins['XEP-0277'] = plugin_xep_0277.XEP_0277(self.host) | |
144 self.plugin = plugin_misc_groupblog.GroupBlog(self.host) | |
145 self.plugin._initialise = self._initialise | |
146 self.__initialised = False | |
147 self._initialise(C.PROFILE[0]) | |
148 | |
149 def _initialise(self, profile_key): | |
150 profile = profile_key | |
151 client = self.host.getClient(profile) | |
152 if not self.__initialised: | |
153 client.item_access_pubsub = jid.JID(SERVICE) | |
154 xep_0060 = self.host.plugins['XEP-0060'] | |
155 client.pubsub_client = helpers_plugins.FakeSatPubSubClient(self.host, xep_0060) | |
156 client.pubsub_client.parent = client | |
157 self.psclient = client.pubsub_client | |
158 helpers.FakeSAT.getDiscoItems = self.psclient.service_getDiscoItems | |
159 self.__initialised = True | |
160 return defer.succeed((profile, client)) | |
161 | |
162 def _addItem(self, profile, item, parent_node=None): | |
163 client = self.host.getClient(profile) | |
164 client.pubsub_client._addItem(item, parent_node) | |
165 | |
166 def test_sendGroupBlog(self): | |
167 self._initialise(C.PROFILE[0]) | |
168 d = self.psclient.items(SERVICE, NODE_ID) | |
169 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
170 d.addCallback(lambda dummy: self.plugin.sendGroupBlog('PUBLIC', [], 'test', {}, C.PROFILE[0])) | |
171 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
172 return d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
173 | |
174 def test_deleteGroupBlog(self): | |
175 pub_data = (SERVICE, NODE_ID, ITEM_ID_1) | |
176 self.host.bridge.expectCall('personalEvent', C.JID_STR[0], | |
177 "MICROBLOG_DELETE", | |
178 {'type': 'main_item', 'id': ITEM_ID_1}, | |
179 C.PROFILE[0]) | |
180 | |
181 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
182 d.addCallback(lambda dummy: self.plugin.deleteGroupBlog(pub_data, COMMENTS_NODE_URL_1, profile_key=C.PROFILE[0])) | |
183 return d.addCallback(self.assertEqual, None) | |
184 | |
185 def test_updateGroupBlog(self): | |
186 pub_data = (SERVICE, NODE_ID, ITEM_ID_1) | |
187 new_text = u"silfu23RFWUP)IWNOEIOEFÖ" | |
188 | |
189 self._initialise(C.PROFILE[0]) | |
190 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
191 d.addCallback(lambda dummy: self.plugin.updateGroupBlog(pub_data, COMMENTS_NODE_URL_1, new_text, {}, profile_key=C.PROFILE[0])) | |
192 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
193 return d.addCallback(lambda items: self.assertEqual(''.join(items[0].entry.title.children), new_text)) | |
194 | |
195 def test_sendGroupBlogComment(self): | |
196 self._initialise(C.PROFILE[0]) | |
197 d = self.psclient.items(SERVICE, NODE_ID) | |
198 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
199 d.addCallback(lambda dummy: self.plugin.sendGroupBlogComment(COMMENTS_NODE_URL_1, 'test', {}, profile_key=C.PROFILE[0])) | |
200 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
201 return d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
202 | |
203 def test_getGroupBlogs(self): | |
204 self._initialise(C.PROFILE[0]) | |
205 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
206 d.addCallback(lambda dummy: self.plugin.getGroupBlogs(PUBLISHER, profile_key=C.PROFILE[0])) | |
207 result = ([ITEM_DATA_1()], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1}) | |
208 return d.addCallback(self.assertEqual, result) | |
209 | |
210 def test_getGroupBlogsNoCount(self): | |
211 self._initialise(C.PROFILE[0]) | |
212 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
213 d.addCallback(lambda dummy: self.plugin.getGroupBlogs(PUBLISHER, count_comments=False, profile_key=C.PROFILE[0])) | |
214 result = ([ITEM_DATA_1(DO_NOT_COUNT_COMMENTS)], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1}) | |
215 return d.addCallback(self.assertEqual, result) | |
216 | |
217 def test_getGroupBlogsWithIDs(self): | |
218 self._initialise(C.PROFILE[0]) | |
219 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
220 d.addCallback(lambda dummy: self.plugin.getGroupBlogs(PUBLISHER, [ITEM_ID_1], profile_key=C.PROFILE[0])) | |
221 result = ([ITEM_DATA_1()], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1}) | |
222 return d.addCallback(self.assertEqual, result) | |
223 | |
224 def test_getGroupBlogsWithRSM(self): | |
225 self._initialise(C.PROFILE[0]) | |
226 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
227 d.addCallback(lambda dummy: self.plugin.getGroupBlogs(PUBLISHER, rsm_data={'max_': 1}, profile_key=C.PROFILE[0])) | |
228 result = ([ITEM_DATA_1()], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1}) | |
229 return d.addCallback(self.assertEqual, result) | |
230 | |
231 def test_getGroupBlogsWithComments(self): | |
232 self._initialise(C.PROFILE[0]) | |
233 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
234 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1])) | |
235 d.addCallback(lambda dummy: self.plugin.getGroupBlogsWithComments(PUBLISHER, [], profile_key=C.PROFILE[0])) | |
236 result = ([(ITEM_DATA_1(1), ([COMMENT_DATA_1], | |
237 {'count': '1', 'index': '0', 'first': COMMENT_ID_1, 'last': COMMENT_ID_1}))], | |
238 {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1}) | |
239 return d.addCallback(self.assertEqual, result) | |
240 | |
241 def test_getGroupBlogsWithComments2(self): | |
242 self._initialise(C.PROFILE[0]) | |
243 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
244 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2])) | |
245 d.addCallback(lambda dummy: self.plugin.getGroupBlogsWithComments(PUBLISHER, [], profile_key=C.PROFILE[0])) | |
246 result = ([(ITEM_DATA_1(2), ([COMMENT_DATA_1, COMMENT_DATA_2], | |
247 {'count': '2', 'index': '0', 'first': COMMENT_ID_1, 'last': COMMENT_ID_2}))], | |
248 {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1}) | |
249 | |
250 return d.addCallback(self.assertEqual, result) | |
251 | |
252 def test_getGroupBlogsAtom(self): | |
253 self._initialise(C.PROFILE[0]) | |
254 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
255 d.addCallback(lambda dummy: self.plugin.getGroupBlogsAtom(PUBLISHER, {'max_': 1}, profile_key=C.PROFILE[0])) | |
256 | |
257 def cb(atom): | |
258 self.assertIsInstance(atom, unicode) | |
259 self.assertTrue(atom.startswith('<?xml version="1.0" encoding="utf-8"?>')) | |
260 | |
261 return d.addCallback(cb) | |
262 | |
263 def test_getMassiveGroupBlogs(self): | |
264 self._initialise(C.PROFILE[0]) | |
265 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
266 d.addCallback(lambda dummy: self.plugin.getMassiveGroupBlogs('JID', [jid.JID(PUBLISHER)], {'max_': 1}, profile_key=C.PROFILE[0])) | |
267 result = {PUBLISHER: ([ITEM_DATA_1()], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1})} | |
268 | |
269 def clean(res): | |
270 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@found@' + SERVICE] | |
271 return res | |
272 | |
273 d.addCallback(clean) | |
274 d.addCallback(self.assertEqual, result) | |
275 | |
276 def test_getMassiveGroupBlogsWithComments(self): | |
277 self._initialise(C.PROFILE[0]) | |
278 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
279 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2])) | |
280 d.addCallback(lambda dummy: self.plugin.getMassiveGroupBlogs('JID', [jid.JID(PUBLISHER)], {'max_': 1}, profile_key=C.PROFILE[0])) | |
281 result = {PUBLISHER: ([ITEM_DATA_1(2)], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1})} | |
282 | |
283 def clean(res): | |
284 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@found@' + SERVICE] | |
285 return res | |
286 | |
287 d.addCallback(clean) | |
288 d.addCallback(self.assertEqual, result) | |
289 | |
290 def test_getGroupBlogComments(self): | |
291 self._initialise(C.PROFILE[0]) | |
292 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
293 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1])) | |
294 d.addCallback(lambda dummy: self.plugin.getGroupBlogComments(SERVICE, COMMENTS_NODE_ID_1, {'max_': 1}, profile_key=C.PROFILE[0])) | |
295 result = ([COMMENT_DATA_1], {'count': '1', 'index': '0', 'first': COMMENT_ID_1, 'last': COMMENT_ID_1}) | |
296 return d.addCallback(self.assertEqual, result) | |
297 | |
298 def test_subscribeGroupBlog(self): | |
299 self._initialise(C.PROFILE[0]) | |
300 d = self.plugin.subscribeGroupBlog(PUBLISHER, profile_key=C.PROFILE[0]) | |
301 return d.addCallback(self.assertEqual, None) | |
302 | |
303 def test_massiveSubscribeGroupBlogs(self): | |
304 self._initialise(C.PROFILE[0]) | |
305 d = self.plugin.massiveSubscribeGroupBlogs('JID', [jid.JID(PUBLISHER)], profile_key=C.PROFILE[0]) | |
306 | |
307 def clean(res): | |
308 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@found@' + SERVICE] | |
309 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@subscriptions@' + SERVICE] | |
310 return res | |
311 | |
312 d.addCallback(clean) | |
313 return d.addCallback(self.assertEqual, None) | |
314 | |
315 def test_deleteAllGroupBlogs(self): | |
316 """Delete our main node and associated comments node""" | |
317 self._initialise(C.PROFILE[0]) | |
318 self.host.profiles[C.PROFILE[0]].roster.addItem(jid.JID(OTHER_PUBLISHER)) | |
319 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
320 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2])) | |
321 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
322 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
323 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
324 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
325 | |
326 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, OTHER_NODE_ID, [ITEM_2])) | |
327 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_2, [COMMENT_1, COMMENT_2])) | |
328 d.addCallback(lambda dummy: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
329 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
330 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
331 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
332 | |
333 def clean(res): | |
334 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@found@' + SERVICE] | |
335 return res | |
336 | |
337 d.addCallback(lambda dummy: self.plugin.deleteAllGroupBlogs(C.PROFILE[0])) | |
338 d.addCallback(clean) | |
339 | |
340 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
341 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
342 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
343 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
344 | |
345 d.addCallback(lambda dummy: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
346 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
347 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
348 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
349 return d | |
350 | |
351 def test_deleteAllGroupBlogsComments(self): | |
352 """Delete the comments we posted on other node's""" | |
353 self._initialise(C.PROFILE[0]) | |
354 self.host.profiles[C.PROFILE[0]].roster.addItem(jid.JID(OTHER_PUBLISHER)) | |
355 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
356 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2])) | |
357 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
358 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
359 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
360 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
361 | |
362 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, OTHER_NODE_ID, [ITEM_2])) | |
363 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_2, [COMMENT_1, COMMENT_2])) | |
364 d.addCallback(lambda dummy: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
365 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
366 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
367 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
368 | |
369 def clean(res): | |
370 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@found@' + SERVICE] | |
371 return res | |
372 | |
373 d.addCallback(lambda dummy: self.plugin.deleteAllGroupBlogsComments(C.PROFILE[0])) | |
374 d.addCallback(clean) | |
375 | |
376 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
377 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
378 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
379 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
380 | |
381 d.addCallback(lambda dummy: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
382 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
383 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
384 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
385 return d | |
386 | |
387 def test_deleteAllGroupBlogsAndComments(self): | |
388 self._initialise(C.PROFILE[0]) | |
389 self.host.profiles[C.PROFILE[0]].roster.addItem(jid.JID(OTHER_PUBLISHER)) | |
390 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
391 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2])) | |
392 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
393 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
394 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
395 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
396 | |
397 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, OTHER_NODE_ID, [ITEM_2])) | |
398 d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_2, [COMMENT_1, COMMENT_2])) | |
399 d.addCallback(lambda dummy: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
400 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
401 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
402 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
403 | |
404 def clean(res): | |
405 del self.host.plugins['XEP-0060'].node_cache[C.PROFILE[0] + '@found@' + SERVICE] | |
406 return res | |
407 | |
408 d.addCallback(lambda dummy: self.plugin.deleteAllGroupBlogsAndComments(C.PROFILE[0])) | |
409 d.addCallback(clean) | |
410 | |
411 d.addCallback(lambda dummy: self.psclient.items(SERVICE, NODE_ID)) | |
412 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
413 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
414 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
415 | |
416 d.addCallback(lambda dummy: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
417 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
418 d.addCallback(lambda dummy: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
419 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
420 return d |