2 from slixmpp
.test
import SlixTest
3 import slixmpp
.plugins
.xep_0004
as xep_0004
4 import slixmpp
.plugins
.xep_0060
.stanza
as pubsub
5 from slixmpp
.xmlstream
.stanzabase
import ET
8 class TestPubsubStanzas(SlixTest
):
10 def testAffiliations(self
):
11 "Testing iq/pubsub/affiliations/affiliation stanzas"
13 aff1
= pubsub
.Affiliation()
14 aff1
['node'] = 'testnode'
15 aff1
['affiliation'] = 'owner'
16 aff2
= pubsub
.Affiliation()
17 aff2
['node'] = 'testnode2'
18 aff2
['affiliation'] = 'publisher'
19 iq
['pubsub']['affiliations'].append(aff1
)
20 iq
['pubsub']['affiliations'].append(aff2
)
23 <pubsub xmlns="http://jabber.org/protocol/pubsub">
25 <affiliation node="testnode" affiliation="owner" />
26 <affiliation node="testnode2" affiliation="publisher" />
31 def testSubscriptions(self
):
32 "Testing iq/pubsub/subscriptions/subscription stanzas"
34 sub1
= pubsub
.Subscription()
35 sub1
['node'] = 'testnode'
36 sub1
['jid'] = 'steve@myserver.tld/someresource'
37 sub2
= pubsub
.Subscription()
38 sub2
['node'] = 'testnode2'
39 sub2
['jid'] = 'boogers@bork.top/bill'
40 sub2
['subscription'] = 'subscribed'
41 iq
['pubsub']['subscriptions'].append(sub1
)
42 iq
['pubsub']['subscriptions'].append(sub2
)
45 <pubsub xmlns="http://jabber.org/protocol/pubsub">
47 <subscription node="testnode" jid="steve@myserver.tld/someresource" />
48 <subscription node="testnode2" jid="boogers@bork.top/bill" subscription="subscribed" />
53 def testOptionalSettings(self
):
54 "Testing iq/pubsub/subscription/subscribe-options stanzas"
56 iq
['pubsub']['subscription']['suboptions']['required'] = True
57 iq
['pubsub']['subscription']['node'] = 'testnode alsdkjfas'
58 iq
['pubsub']['subscription']['jid'] = "fritzy@netflint.net/slixmpp"
59 iq
['pubsub']['subscription']['subscription'] = 'unconfigured'
62 <pubsub xmlns="http://jabber.org/protocol/pubsub">
63 <subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/slixmpp" subscription="unconfigured">
72 "Testing iq/pubsub/items stanzas"
74 iq
['pubsub']['items']['node'] = 'crap'
75 payload
= ET
.fromstring("""
76 <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
78 <child2 normandy='cheese' foo='bar' />
80 payload2
= ET
.fromstring("""
81 <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
83 <child22 normandy='cheese2' foo='bar2' />
87 item
['payload'] = payload
90 item2
['payload'] = payload2
91 iq
['pubsub']['items'].append(item
)
92 iq
['pubsub']['items'].append(item2
)
95 <pubsub xmlns="http://jabber.org/protocol/pubsub">
98 <thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
100 <child2 foo="bar" normandy="cheese" />
104 <thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
106 <child22 foo="bar2" normandy="cheese2" />
113 def testCreate(self
):
114 "Testing iq/pubsub/create&configure stanzas"
116 iq
['pubsub']['create']['node'] = 'mynode'
117 iq
['pubsub']['configure']['form'].addField('pubsub#title',
119 value
='This thing is awesome')
122 <pubsub xmlns="http://jabber.org/protocol/pubsub">
123 <create node="mynode" />
125 <x xmlns="jabber:x:data" type="form">
126 <field var="pubsub#title" type="text-single">
127 <value>This thing is awesome</value>
134 def testDefault(self
):
135 "Testing iq/pubsub_owner/default stanzas"
137 iq
['pubsub_owner']['default']
138 iq
['pubsub_owner']['default']['node'] = 'mynode'
139 iq
['pubsub_owner']['default']['form'].addField('pubsub#title',
141 value
='This thing is awesome')
144 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
145 <default node="mynode">
146 <x xmlns="jabber:x:data" type="form">
147 <field var="pubsub#title" type="text-single">
148 <value>This thing is awesome</value>
153 </iq>""", use_values
=False)
155 def testSubscribe(self
):
156 "testing iq/pubsub/subscribe stanzas"
158 iq
['pubsub']['subscribe']['options']
159 iq
['pubsub']['subscribe']['node'] = 'cheese'
160 iq
['pubsub']['subscribe']['jid'] = 'fritzy@netflint.net/slixmpp'
161 iq
['pubsub']['subscribe']['options']['node'] = 'cheese'
162 iq
['pubsub']['subscribe']['options']['jid'] = 'fritzy@netflint.net/slixmpp'
163 form
= xep_0004
.Form()
164 form
.addField('pubsub#title', ftype
='text-single', value
='this thing is awesome')
165 iq
['pubsub']['subscribe']['options']['options'] = form
168 <pubsub xmlns="http://jabber.org/protocol/pubsub">
169 <subscribe node="cheese" jid="fritzy@netflint.net/slixmpp">
170 <options node="cheese" jid="fritzy@netflint.net/slixmpp">
171 <x xmlns="jabber:x:data" type="submit">
172 <field var="pubsub#title">
173 <value>this thing is awesome</value>
179 </iq>""", use_values
=False)
181 def testPublish(self
):
182 "Testing iq/pubsub/publish stanzas"
184 iq
['pubsub']['publish']['node'] = 'thingers'
185 payload
= ET
.fromstring("""
186 <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
188 <child2 normandy='cheese' foo='bar' />
190 payload2
= ET
.fromstring("""
191 <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
193 <child22 normandy='cheese2' foo='bar2' />
197 item
['payload'] = payload
198 item2
= pubsub
.Item()
199 item2
['id'] = 'asdf2'
200 item2
['payload'] = payload2
201 iq
['pubsub']['publish'].append(item
)
202 iq
['pubsub']['publish'].append(item2
)
203 form
= xep_0004
.Form()
204 form
.addField('pubsub#description', ftype
='text-single', value
='this thing is awesome')
205 iq
['pubsub']['publish_options'] = form
209 <pubsub xmlns="http://jabber.org/protocol/pubsub">
210 <publish node="thingers">
212 <thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
214 <child2 foo="bar" normandy="cheese" />
218 <thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
220 <child22 foo="bar2" normandy="cheese2" />
225 <x xmlns="jabber:x:data" type="submit">
226 <field var="pubsub#description">
227 <value>this thing is awesome</value>
234 def testDelete(self
):
235 "Testing iq/pubsub_owner/delete stanzas"
237 iq
['pubsub_owner']['delete']['node'] = 'thingers'
240 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
241 <delete node="thingers" />
245 def testCreateConfigGet(self
):
246 """Testing getting config from full create"""
248 iq
['to'] = 'pubsub.asdf'
249 iq
['from'] = 'fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7'
254 pub
['create']['node'] = 'testnode2'
255 pub
['configure']['form']['type'] = 'submit'
256 pub
['configure']['form'].setFields([
257 ('FORM_TYPE', {'type': 'hidden',
258 'value': 'http://jabber.org/protocol/pubsub#node_config'}),
259 ('pubsub#node_type', {'type': 'list-single',
260 'label': 'Select the node type',
262 ('pubsub#title', {'type': 'text-single',
263 'label': 'A friendly name for the node'}),
264 ('pubsub#deliver_notifications', {'type': 'boolean',
265 'label': 'Deliver event notifications',
267 ('pubsub#deliver_payloads', {'type': 'boolean',
268 'label': 'Deliver payloads with event notifications',
270 ('pubsub#notify_config', {'type': 'boolean',
271 'label': 'Notify subscribers when the node configuration changes'}),
272 ('pubsub#notify_delete', {'type': 'boolean',
273 'label': 'Notify subscribers when the node is deleted'}),
274 ('pubsub#notify_retract', {'type': 'boolean',
275 'label': 'Notify subscribers when items are removed from the node',
277 ('pubsub#notify_sub', {'type': 'boolean',
278 'label': 'Notify owners about new subscribers and unsubscribes'}),
279 ('pubsub#persist_items', {'type': 'boolean',
280 'label': 'Persist items in storage'}),
281 ('pubsub#max_items', {'type': 'text-single',
282 'label': 'Max # of items to persist',
284 ('pubsub#subscribe', {'type': 'boolean',
285 'label': 'Whether to allow subscriptions',
287 ('pubsub#access_model', {'type': 'list-single',
288 'label': 'Specify the subscriber model',
290 ('pubsub#publish_model', {'type': 'list-single',
291 'label': 'Specify the publisher model',
292 'value': 'publishers'}),
293 ('pubsub#send_last_published_item', {'type': 'list-single',
294 'label': 'Send last published item',
296 ('pubsub#presence_based_delivery', {'type': 'boolean',
297 'label': 'Deliver notification only to available users'}),
301 <iq to="pubsub.asdf" type="set" id="E" from="fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7">
302 <pubsub xmlns="http://jabber.org/protocol/pubsub">
303 <create node="testnode2" />
305 <x xmlns="jabber:x:data" type="submit">
306 <field var="FORM_TYPE">
307 <value>http://jabber.org/protocol/pubsub#node_config</value>
309 <field var="pubsub#node_type">
312 <field var="pubsub#title" />
313 <field var="pubsub#deliver_notifications">
316 <field var="pubsub#deliver_payloads">
319 <field var="pubsub#notify_config" />
320 <field var="pubsub#notify_delete" />
321 <field var="pubsub#notify_retract">
324 <field var="pubsub#notify_sub" />
325 <field var="pubsub#persist_items" />
326 <field var="pubsub#max_items">
329 <field var="pubsub#subscribe">
332 <field var="pubsub#access_model">
335 <field var="pubsub#publish_model">
336 <value>publishers</value>
338 <field var="pubsub#send_last_published_item">
341 <field var="pubsub#presence_based_delivery" />
347 def testItemEvent(self
):
348 """Testing message/pubsub_event/items/item"""
350 item
= pubsub
.EventItem()
351 pl
= ET
.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
353 item
['id'] = 'abc123'
354 msg
['pubsub_event']['items'].append(item
)
355 msg
['pubsub_event']['items']['node'] = 'cheese'
356 msg
['type'] = 'normal'
358 <message type="normal">
359 <event xmlns="http://jabber.org/protocol/pubsub#event">
360 <items node="cheese">
362 <test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
368 def testItemsEvent(self
):
369 """Testing multiple message/pubsub_event/items/item"""
371 item
= pubsub
.EventItem()
372 item2
= pubsub
.EventItem()
373 pl
= ET
.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
374 pl2
= ET
.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
375 item2
['payload'] = pl2
377 item
['id'] = 'abc123'
378 item2
['id'] = '123abc'
379 msg
['pubsub_event']['items'].append(item
)
380 msg
['pubsub_event']['items'].append(item2
)
381 msg
['pubsub_event']['items']['node'] = 'cheese'
382 msg
['type'] = 'normal'
384 <message type="normal">
385 <event xmlns="http://jabber.org/protocol/pubsub#event">
386 <items node="cheese">
388 <test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
391 <test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
397 def testItemsEvent(self
):
398 """Testing message/pubsub_event/items/item & retract mix"""
400 item
= pubsub
.EventItem()
401 item2
= pubsub
.EventItem()
402 pl
= ET
.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
403 pl2
= ET
.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
404 item2
['payload'] = pl2
405 retract
= pubsub
.EventRetract()
406 retract
['id'] = 'aabbcc'
408 item
['id'] = 'abc123'
409 item2
['id'] = '123abc'
410 msg
['pubsub_event']['items'].append(item
)
411 msg
['pubsub_event']['items'].append(retract
)
412 msg
['pubsub_event']['items'].append(item2
)
413 msg
['pubsub_event']['items']['node'] = 'cheese'
414 msg
['type'] = 'normal'
416 <message type="normal">
417 <event xmlns="http://jabber.org/protocol/pubsub#event">
418 <items node="cheese">
420 <test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
421 </item><retract id="aabbcc" />
423 <test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
429 def testCollectionAssociate(self
):
430 """Testing message/pubsub_event/collection/associate"""
432 msg
['pubsub_event']['collection']['associate']['node'] = 'cheese'
433 msg
['pubsub_event']['collection']['node'] = 'cheeseburger'
434 msg
['type'] = 'headline'
436 <message type="headline">
437 <event xmlns="http://jabber.org/protocol/pubsub#event">
438 <collection node="cheeseburger">
439 <associate node="cheese" />
444 def testCollectionDisassociate(self
):
445 """Testing message/pubsub_event/collection/disassociate"""
447 msg
['pubsub_event']['collection']['disassociate']['node'] = 'cheese'
448 msg
['pubsub_event']['collection']['node'] = 'cheeseburger'
449 msg
['type'] = 'headline'
451 <message type="headline">
452 <event xmlns="http://jabber.org/protocol/pubsub#event">
453 <collection node="cheeseburger">
454 <disassociate node="cheese" />
459 def testEventConfiguration(self
):
460 """Testing message/pubsub_event/configuration/config"""
462 msg
['pubsub_event']['configuration']['node'] = 'cheese'
463 msg
['pubsub_event']['configuration']['form'].addField('pubsub#title',
465 value
='This thing is awesome')
466 msg
['type'] = 'headline'
468 <message type="headline">
469 <event xmlns="http://jabber.org/protocol/pubsub#event">
470 <configuration node="cheese">
471 <x xmlns="jabber:x:data" type="form">
472 <field var="pubsub#title" type="text-single">
473 <value>This thing is awesome</value>
480 def testEventPurge(self
):
481 """Testing message/pubsub_event/purge"""
483 msg
['pubsub_event']['purge']['node'] = 'pickles'
484 msg
['type'] = 'headline'
486 <message type="headline">
487 <event xmlns="http://jabber.org/protocol/pubsub#event">
488 <purge node="pickles" />
492 def testEventSubscription(self
):
493 """Testing message/pubsub_event/subscription"""
495 msg
['pubsub_event']['subscription']['node'] = 'pickles'
496 msg
['pubsub_event']['subscription']['jid'] = 'fritzy@netflint.net/test'
497 msg
['pubsub_event']['subscription']['subid'] = 'aabb1122'
498 msg
['pubsub_event']['subscription']['subscription'] = 'subscribed'
499 msg
['pubsub_event']['subscription']['expiry'] = 'presence'
500 msg
['type'] = 'headline'
502 <message type="headline">
503 <event xmlns="http://jabber.org/protocol/pubsub#event">
504 <subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" />
508 def testPubsubError(self
):
509 """Test getting a pubsub specific condition from an error stanza"""
511 iq
['error']['type'] = 'cancel'
512 iq
['error']['code'] = '501'
513 iq
['error']['condition'] = 'feature-not-implemented'
514 iq
['error']['pubsub']['condition'] = 'subid-required'
517 <error type="cancel" code="501">
518 <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
519 <subid-required xmlns="http://jabber.org/protocol/pubsub#errors" />
522 """, use_values
=False)
524 del iq
['error']['pubsub']['condition']
527 <error type="cancel" code="501">
528 <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
531 """, use_values
=False)
533 def testPubsubUnsupportedError(self
):
534 """Test getting the feature from an unsupported error"""
536 iq
['error']['type'] = 'cancel'
537 iq
['error']['code'] = '501'
538 iq
['error']['condition'] = 'feature-not-implemented'
539 iq
['error']['pubsub']['condition'] = 'unsupported'
540 iq
['error']['pubsub']['unsupported'] = 'instant-node'
543 <error type="cancel" code="501">
544 <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
545 <unsupported xmlns="http://jabber.org/protocol/pubsub#errors" feature="instant-node" />
548 """, use_values
=False)
550 self
.assertEqual(iq
['error']['pubsub']['condition'], 'unsupported')
551 self
.assertEqual(iq
['error']['pubsub']['unsupported'], 'instant-node')
553 del iq
['error']['pubsub']['unsupported']
556 <error type="cancel" code="501">
557 <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
560 """, use_values
=False)
563 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestPubsubStanzas
)