comparison sat/test/test_plugin_misc_groupblog.py @ 2624:56f94936df1e

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