Mercurial > libervia-backend
comparison libervia/backend/test/test_plugin_misc_groupblog.py @ 4071:4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 11:49:51 +0200 |
parents | sat/test/test_plugin_misc_groupblog.py@524856bd7b19 |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4070:d10748475025 | 4071:4b842c1fb686 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 # SAT: a jabber client | |
5 # Copyright (C) 2009-2021 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 libervia.backend.test import helpers, helpers_plugins | |
25 from libervia.backend.plugins import plugin_misc_groupblog | |
26 from libervia.backend.plugins import plugin_xep_0060 | |
27 from libervia.backend.plugins import plugin_xep_0277 | |
28 from libervia.backend.plugins import plugin_xep_0163 | |
29 from libervia.backend.plugins import plugin_misc_text_syntaxes | |
30 from twisted.internet import defer | |
31 from twisted.words.protocols.jabber import jid | |
32 import importlib | |
33 | |
34 | |
35 NS_PUBSUB = "http://jabber.org/protocol/pubsub" | |
36 | |
37 DO_NOT_COUNT_COMMENTS = -1 | |
38 | |
39 SERVICE = "pubsub.example.com" | |
40 PUBLISHER = "test@example.org" | |
41 OTHER_PUBLISHER = "other@xmpp.net" | |
42 NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER) | |
43 OTHER_NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER) | |
44 ITEM_ID_1 = "c745a688-9b02-11e3-a1a3-c0143dd4fe51" | |
45 COMMENT_ID_1 = "d745a688-9b02-11e3-a1a3-c0143dd4fe52" | |
46 COMMENT_ID_2 = "e745a688-9b02-11e3-a1a3-c0143dd4fe53" | |
47 | |
48 | |
49 def COMMENTS_NODE_ID(publisher=PUBLISHER): | |
50 return "urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format( | |
51 id=ITEM_ID_1, publisher=publisher | |
52 ) | |
53 | |
54 | |
55 def COMMENTS_NODE_URL(publisher=PUBLISHER): | |
56 return "xmpp:{service}?node={node}".format( | |
57 service=SERVICE, | |
58 id=ITEM_ID_1, | |
59 node=COMMENTS_NODE_ID(publisher).replace(":", "%3A").replace("@", "%40"), | |
60 ) | |
61 | |
62 | |
63 def ITEM(publisher=PUBLISHER): | |
64 return """ | |
65 <item id='{id}' xmlns='{ns}'> | |
66 <entry> | |
67 <title type='text'>The Uses of This World</title> | |
68 <id>{id}</id> | |
69 <updated>2003-12-12T17:47:23Z</updated> | |
70 <published>2003-12-12T17:47:23Z</published> | |
71 <link href='{comments_node_url}' rel='replies' title='comments'/> | |
72 <author> | |
73 <name>{publisher}</name> | |
74 </author> | |
75 </entry> | |
76 </item> | |
77 """.format( | |
78 ns=NS_PUBSUB, | |
79 id=ITEM_ID_1, | |
80 publisher=publisher, | |
81 comments_node_url=COMMENTS_NODE_URL(publisher), | |
82 ) | |
83 | |
84 | |
85 def COMMENT(id_=COMMENT_ID_1): | |
86 return """ | |
87 <item id='{id}' xmlns='{ns}'> | |
88 <entry> | |
89 <title type='text'>The Uses of This World</title> | |
90 <id>{id}</id> | |
91 <updated>2003-12-12T17:47:23Z</updated> | |
92 <published>2003-12-12T17:47:23Z</published> | |
93 <author> | |
94 <name>{publisher}</name> | |
95 </author> | |
96 </entry> | |
97 </item> | |
98 """.format( | |
99 ns=NS_PUBSUB, id=id_, publisher=PUBLISHER | |
100 ) | |
101 | |
102 | |
103 def ITEM_DATA(id_=ITEM_ID_1, count=0): | |
104 res = { | |
105 "id": ITEM_ID_1, | |
106 "type": "main_item", | |
107 "content": "The Uses of This World", | |
108 "author": PUBLISHER, | |
109 "updated": "1071251243.0", | |
110 "published": "1071251243.0", | |
111 "service": SERVICE, | |
112 "comments": COMMENTS_NODE_URL_1, | |
113 "comments_service": SERVICE, | |
114 "comments_node": COMMENTS_NODE_ID_1, | |
115 } | |
116 if count != DO_NOT_COUNT_COMMENTS: | |
117 res.update({"comments_count": str(count)}) | |
118 return res | |
119 | |
120 | |
121 def COMMENT_DATA(id_=COMMENT_ID_1): | |
122 return { | |
123 "id": id_, | |
124 "type": "comment", | |
125 "content": "The Uses of This World", | |
126 "author": PUBLISHER, | |
127 "updated": "1071251243.0", | |
128 "published": "1071251243.0", | |
129 "service": SERVICE, | |
130 "node": COMMENTS_NODE_ID_1, | |
131 "verified_publisher": "false", | |
132 } | |
133 | |
134 | |
135 COMMENTS_NODE_ID_1 = COMMENTS_NODE_ID() | |
136 COMMENTS_NODE_ID_2 = COMMENTS_NODE_ID(OTHER_PUBLISHER) | |
137 COMMENTS_NODE_URL_1 = COMMENTS_NODE_URL() | |
138 COMMENTS_NODE_URL_2 = COMMENTS_NODE_URL(OTHER_PUBLISHER) | |
139 ITEM_1 = ITEM() | |
140 ITEM_2 = ITEM(OTHER_PUBLISHER) | |
141 COMMENT_1 = COMMENT(COMMENT_ID_1) | |
142 COMMENT_2 = COMMENT(COMMENT_ID_2) | |
143 | |
144 | |
145 def ITEM_DATA_1(count=0): | |
146 return ITEM_DATA(count=count) | |
147 | |
148 | |
149 COMMENT_DATA_1 = COMMENT_DATA() | |
150 COMMENT_DATA_2 = COMMENT_DATA(COMMENT_ID_2) | |
151 | |
152 | |
153 class XEP_groupblogTest(helpers.SatTestCase): | |
154 def setUp(self): | |
155 self.host = helpers.FakeSAT() | |
156 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host) | |
157 self.host.plugins["XEP-0163"] = plugin_xep_0163.XEP_0163(self.host) | |
158 importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error | |
159 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes( | |
160 self.host | |
161 ) | |
162 self.host.plugins["XEP-0277"] = plugin_xep_0277.XEP_0277(self.host) | |
163 self.plugin = plugin_misc_groupblog.GroupBlog(self.host) | |
164 self.plugin._initialise = self._initialise | |
165 self.__initialised = False | |
166 self._initialise(C.PROFILE[0]) | |
167 | |
168 def _initialise(self, profile_key): | |
169 profile = profile_key | |
170 client = self.host.get_client(profile) | |
171 if not self.__initialised: | |
172 client.item_access_pubsub = jid.JID(SERVICE) | |
173 xep_0060 = self.host.plugins["XEP-0060"] | |
174 client.pubsub_client = helpers_plugins.FakeSatPubSubClient( | |
175 self.host, xep_0060 | |
176 ) | |
177 client.pubsub_client.parent = client | |
178 self.psclient = client.pubsub_client | |
179 helpers.FakeSAT.getDiscoItems = self.psclient.service_get_disco_items | |
180 self.__initialised = True | |
181 return defer.succeed((profile, client)) | |
182 | |
183 def _add_item(self, profile, item, parent_node=None): | |
184 client = self.host.get_client(profile) | |
185 client.pubsub_client._add_item(item, parent_node) | |
186 | |
187 def test_send_group_blog(self): | |
188 self._initialise(C.PROFILE[0]) | |
189 d = self.psclient.items(SERVICE, NODE_ID) | |
190 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
191 d.addCallback( | |
192 lambda __: self.plugin.sendGroupBlog( | |
193 "PUBLIC", [], "test", {}, C.PROFILE[0] | |
194 ) | |
195 ) | |
196 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
197 return d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
198 | |
199 def test_delete_group_blog(self): | |
200 pub_data = (SERVICE, NODE_ID, ITEM_ID_1) | |
201 self.host.bridge.expect_call( | |
202 "personalEvent", | |
203 C.JID_STR[0], | |
204 "MICROBLOG_DELETE", | |
205 {"type": "main_item", "id": ITEM_ID_1}, | |
206 C.PROFILE[0], | |
207 ) | |
208 | |
209 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
210 d.addCallback( | |
211 lambda __: self.plugin.deleteGroupBlog( | |
212 pub_data, COMMENTS_NODE_URL_1, profile_key=C.PROFILE[0] | |
213 ) | |
214 ) | |
215 return d.addCallback(self.assertEqual, None) | |
216 | |
217 def test_update_group_blog(self): | |
218 pub_data = (SERVICE, NODE_ID, ITEM_ID_1) | |
219 new_text = "silfu23RFWUP)IWNOEIOEFÖ" | |
220 | |
221 self._initialise(C.PROFILE[0]) | |
222 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
223 d.addCallback( | |
224 lambda __: self.plugin.updateGroupBlog( | |
225 pub_data, COMMENTS_NODE_URL_1, new_text, {}, profile_key=C.PROFILE[0] | |
226 ) | |
227 ) | |
228 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
229 return d.addCallback( | |
230 lambda items: self.assertEqual( | |
231 "".join(items[0].entry.title.children), new_text | |
232 ) | |
233 ) | |
234 | |
235 def test_send_group_blog_comment(self): | |
236 self._initialise(C.PROFILE[0]) | |
237 d = self.psclient.items(SERVICE, NODE_ID) | |
238 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
239 d.addCallback( | |
240 lambda __: self.plugin.sendGroupBlogComment( | |
241 COMMENTS_NODE_URL_1, "test", {}, profile_key=C.PROFILE[0] | |
242 ) | |
243 ) | |
244 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
245 return d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
246 | |
247 def test_get_group_blogs(self): | |
248 self._initialise(C.PROFILE[0]) | |
249 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
250 d.addCallback( | |
251 lambda __: self.plugin.getGroupBlogs(PUBLISHER, profile_key=C.PROFILE[0]) | |
252 ) | |
253 result = ( | |
254 [ITEM_DATA_1()], | |
255 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
256 ) | |
257 return d.addCallback(self.assertEqual, result) | |
258 | |
259 def test_get_group_blogs_no_count(self): | |
260 self._initialise(C.PROFILE[0]) | |
261 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
262 d.addCallback( | |
263 lambda __: self.plugin.getGroupBlogs( | |
264 PUBLISHER, count_comments=False, profile_key=C.PROFILE[0] | |
265 ) | |
266 ) | |
267 result = ( | |
268 [ITEM_DATA_1(DO_NOT_COUNT_COMMENTS)], | |
269 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
270 ) | |
271 return d.addCallback(self.assertEqual, result) | |
272 | |
273 def test_get_group_blogs_with_i_ds(self): | |
274 self._initialise(C.PROFILE[0]) | |
275 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
276 d.addCallback( | |
277 lambda __: self.plugin.getGroupBlogs( | |
278 PUBLISHER, [ITEM_ID_1], profile_key=C.PROFILE[0] | |
279 ) | |
280 ) | |
281 result = ( | |
282 [ITEM_DATA_1()], | |
283 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
284 ) | |
285 return d.addCallback(self.assertEqual, result) | |
286 | |
287 def test_get_group_blogs_with_rsm(self): | |
288 self._initialise(C.PROFILE[0]) | |
289 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
290 d.addCallback( | |
291 lambda __: self.plugin.getGroupBlogs( | |
292 PUBLISHER, rsm_data={"max_": 1}, profile_key=C.PROFILE[0] | |
293 ) | |
294 ) | |
295 result = ( | |
296 [ITEM_DATA_1()], | |
297 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
298 ) | |
299 return d.addCallback(self.assertEqual, result) | |
300 | |
301 def test_get_group_blogs_with_comments(self): | |
302 self._initialise(C.PROFILE[0]) | |
303 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
304 d.addCallback( | |
305 lambda __: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1]) | |
306 ) | |
307 d.addCallback( | |
308 lambda __: self.plugin.getGroupBlogsWithComments( | |
309 PUBLISHER, [], profile_key=C.PROFILE[0] | |
310 ) | |
311 ) | |
312 result = ( | |
313 [ | |
314 ( | |
315 ITEM_DATA_1(1), | |
316 ( | |
317 [COMMENT_DATA_1], | |
318 { | |
319 "count": "1", | |
320 "index": "0", | |
321 "first": COMMENT_ID_1, | |
322 "last": COMMENT_ID_1, | |
323 }, | |
324 ), | |
325 ) | |
326 ], | |
327 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
328 ) | |
329 return d.addCallback(self.assertEqual, result) | |
330 | |
331 def test_get_group_blogs_with_comments_2(self): | |
332 self._initialise(C.PROFILE[0]) | |
333 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
334 d.addCallback( | |
335 lambda __: self.psclient.publish( | |
336 SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2] | |
337 ) | |
338 ) | |
339 d.addCallback( | |
340 lambda __: self.plugin.getGroupBlogsWithComments( | |
341 PUBLISHER, [], profile_key=C.PROFILE[0] | |
342 ) | |
343 ) | |
344 result = ( | |
345 [ | |
346 ( | |
347 ITEM_DATA_1(2), | |
348 ( | |
349 [COMMENT_DATA_1, COMMENT_DATA_2], | |
350 { | |
351 "count": "2", | |
352 "index": "0", | |
353 "first": COMMENT_ID_1, | |
354 "last": COMMENT_ID_2, | |
355 }, | |
356 ), | |
357 ) | |
358 ], | |
359 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
360 ) | |
361 | |
362 return d.addCallback(self.assertEqual, result) | |
363 | |
364 def test_get_group_blogs_atom(self): | |
365 self._initialise(C.PROFILE[0]) | |
366 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
367 d.addCallback( | |
368 lambda __: self.plugin.getGroupBlogsAtom( | |
369 PUBLISHER, {"max_": 1}, profile_key=C.PROFILE[0] | |
370 ) | |
371 ) | |
372 | |
373 def cb(atom): | |
374 self.assertIsInstance(atom, str) | |
375 self.assertTrue(atom.startswith('<?xml version="1.0" encoding="utf-8"?>')) | |
376 | |
377 return d.addCallback(cb) | |
378 | |
379 def test_get_massive_group_blogs(self): | |
380 self._initialise(C.PROFILE[0]) | |
381 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
382 d.addCallback( | |
383 lambda __: self.plugin.getMassiveGroupBlogs( | |
384 "JID", [jid.JID(PUBLISHER)], {"max_": 1}, profile_key=C.PROFILE[0] | |
385 ) | |
386 ) | |
387 result = { | |
388 PUBLISHER: ( | |
389 [ITEM_DATA_1()], | |
390 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
391 ) | |
392 } | |
393 | |
394 def clean(res): | |
395 del self.host.plugins["XEP-0060"].node_cache[ | |
396 C.PROFILE[0] + "@found@" + SERVICE | |
397 ] | |
398 return res | |
399 | |
400 d.addCallback(clean) | |
401 d.addCallback(self.assertEqual, result) | |
402 | |
403 def test_get_massive_group_blogs_with_comments(self): | |
404 self._initialise(C.PROFILE[0]) | |
405 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
406 d.addCallback( | |
407 lambda __: self.psclient.publish( | |
408 SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2] | |
409 ) | |
410 ) | |
411 d.addCallback( | |
412 lambda __: self.plugin.getMassiveGroupBlogs( | |
413 "JID", [jid.JID(PUBLISHER)], {"max_": 1}, profile_key=C.PROFILE[0] | |
414 ) | |
415 ) | |
416 result = { | |
417 PUBLISHER: ( | |
418 [ITEM_DATA_1(2)], | |
419 {"count": "1", "index": "0", "first": ITEM_ID_1, "last": ITEM_ID_1}, | |
420 ) | |
421 } | |
422 | |
423 def clean(res): | |
424 del self.host.plugins["XEP-0060"].node_cache[ | |
425 C.PROFILE[0] + "@found@" + SERVICE | |
426 ] | |
427 return res | |
428 | |
429 d.addCallback(clean) | |
430 d.addCallback(self.assertEqual, result) | |
431 | |
432 def test_get_group_blog_comments(self): | |
433 self._initialise(C.PROFILE[0]) | |
434 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
435 d.addCallback( | |
436 lambda __: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1]) | |
437 ) | |
438 d.addCallback( | |
439 lambda __: self.plugin.getGroupBlogComments( | |
440 SERVICE, COMMENTS_NODE_ID_1, {"max_": 1}, profile_key=C.PROFILE[0] | |
441 ) | |
442 ) | |
443 result = ( | |
444 [COMMENT_DATA_1], | |
445 {"count": "1", "index": "0", "first": COMMENT_ID_1, "last": COMMENT_ID_1}, | |
446 ) | |
447 return d.addCallback(self.assertEqual, result) | |
448 | |
449 def test_subscribe_group_blog(self): | |
450 self._initialise(C.PROFILE[0]) | |
451 d = self.plugin.subscribeGroupBlog(PUBLISHER, profile_key=C.PROFILE[0]) | |
452 return d.addCallback(self.assertEqual, None) | |
453 | |
454 def test_massive_subscribe_group_blogs(self): | |
455 self._initialise(C.PROFILE[0]) | |
456 d = self.plugin.massiveSubscribeGroupBlogs( | |
457 "JID", [jid.JID(PUBLISHER)], profile_key=C.PROFILE[0] | |
458 ) | |
459 | |
460 def clean(res): | |
461 del self.host.plugins["XEP-0060"].node_cache[ | |
462 C.PROFILE[0] + "@found@" + SERVICE | |
463 ] | |
464 del self.host.plugins["XEP-0060"].node_cache[ | |
465 C.PROFILE[0] + "@subscriptions@" + SERVICE | |
466 ] | |
467 return res | |
468 | |
469 d.addCallback(clean) | |
470 return d.addCallback(self.assertEqual, None) | |
471 | |
472 def test_delete_all_group_blogs(self): | |
473 """Delete our main node and associated comments node""" | |
474 self._initialise(C.PROFILE[0]) | |
475 self.host.profiles[C.PROFILE[0]].roster.add_item(jid.JID(OTHER_PUBLISHER)) | |
476 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
477 d.addCallback( | |
478 lambda __: self.psclient.publish( | |
479 SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2] | |
480 ) | |
481 ) | |
482 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
483 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
484 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
485 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
486 | |
487 d.addCallback( | |
488 lambda __: self.psclient.publish(SERVICE, OTHER_NODE_ID, [ITEM_2]) | |
489 ) | |
490 d.addCallback( | |
491 lambda __: self.psclient.publish( | |
492 SERVICE, COMMENTS_NODE_ID_2, [COMMENT_1, COMMENT_2] | |
493 ) | |
494 ) | |
495 d.addCallback(lambda __: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
496 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
497 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
498 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
499 | |
500 def clean(res): | |
501 del self.host.plugins["XEP-0060"].node_cache[ | |
502 C.PROFILE[0] + "@found@" + SERVICE | |
503 ] | |
504 return res | |
505 | |
506 d.addCallback(lambda __: self.plugin.deleteAllGroupBlogs(C.PROFILE[0])) | |
507 d.addCallback(clean) | |
508 | |
509 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
510 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
511 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
512 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
513 | |
514 d.addCallback(lambda __: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
515 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
516 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
517 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
518 return d | |
519 | |
520 def test_delete_all_group_blogs_comments(self): | |
521 """Delete the comments we posted on other node's""" | |
522 self._initialise(C.PROFILE[0]) | |
523 self.host.profiles[C.PROFILE[0]].roster.add_item(jid.JID(OTHER_PUBLISHER)) | |
524 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
525 d.addCallback( | |
526 lambda __: self.psclient.publish( | |
527 SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2] | |
528 ) | |
529 ) | |
530 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
531 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
532 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
533 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
534 | |
535 d.addCallback( | |
536 lambda __: self.psclient.publish(SERVICE, OTHER_NODE_ID, [ITEM_2]) | |
537 ) | |
538 d.addCallback( | |
539 lambda __: self.psclient.publish( | |
540 SERVICE, COMMENTS_NODE_ID_2, [COMMENT_1, COMMENT_2] | |
541 ) | |
542 ) | |
543 d.addCallback(lambda __: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
544 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
545 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
546 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
547 | |
548 def clean(res): | |
549 del self.host.plugins["XEP-0060"].node_cache[ | |
550 C.PROFILE[0] + "@found@" + SERVICE | |
551 ] | |
552 return res | |
553 | |
554 d.addCallback(lambda __: self.plugin.deleteAllGroupBlogsComments(C.PROFILE[0])) | |
555 d.addCallback(clean) | |
556 | |
557 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
558 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
559 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
560 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
561 | |
562 d.addCallback(lambda __: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
563 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
564 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
565 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
566 return d | |
567 | |
568 def test_delete_all_group_blogs_and_comments(self): | |
569 self._initialise(C.PROFILE[0]) | |
570 self.host.profiles[C.PROFILE[0]].roster.add_item(jid.JID(OTHER_PUBLISHER)) | |
571 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) | |
572 d.addCallback( | |
573 lambda __: self.psclient.publish( | |
574 SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2] | |
575 ) | |
576 ) | |
577 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
578 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
579 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
580 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
581 | |
582 d.addCallback( | |
583 lambda __: self.psclient.publish(SERVICE, OTHER_NODE_ID, [ITEM_2]) | |
584 ) | |
585 d.addCallback( | |
586 lambda __: self.psclient.publish( | |
587 SERVICE, COMMENTS_NODE_ID_2, [COMMENT_1, COMMENT_2] | |
588 ) | |
589 ) | |
590 d.addCallback(lambda __: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
591 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
592 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
593 d.addCallback(lambda items: self.assertEqual(len(items), 2)) | |
594 | |
595 def clean(res): | |
596 del self.host.plugins["XEP-0060"].node_cache[ | |
597 C.PROFILE[0] + "@found@" + SERVICE | |
598 ] | |
599 return res | |
600 | |
601 d.addCallback( | |
602 lambda __: self.plugin.deleteAllGroupBlogsAndComments(C.PROFILE[0]) | |
603 ) | |
604 d.addCallback(clean) | |
605 | |
606 d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID)) | |
607 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
608 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1)) | |
609 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
610 | |
611 d.addCallback(lambda __: self.psclient.items(SERVICE, OTHER_NODE_ID)) | |
612 d.addCallback(lambda items: self.assertEqual(len(items), 1)) | |
613 d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_2)) | |
614 d.addCallback(lambda items: self.assertEqual(len(items), 0)) | |
615 return d |