4 from slixmpp
.test
import SlixTest
5 from slixmpp
.stanza
.atom
import AtomEntry
6 from slixmpp
.xmlstream
import register_stanza_plugin
9 class TestStreamPubsub(SlixTest
):
12 Test using the XEP-0030 plugin.
21 def testCreateInstantNode(self
):
22 """Test creating an instant node"""
23 t
= threading
.Thread(name
='create_node',
24 target
=self
.xmpp
['xep_0060'].create_node
,
25 args
=('pubsub.example.com', None))
29 <iq type="set" id="1" to="pubsub.example.com">
30 <pubsub xmlns="http://jabber.org/protocol/pubsub">
37 <iq type="result" id="1"
38 to="tester@localhost" from="pubsub.example.com">
39 <pubsub xmlns="http://jabber.org/protocol/pubsub">
40 <create node="25e3d37dabbab9541f7523321421edc5bfeb2dae" />
47 def testCreateNodeNoConfig(self
):
48 """Test creating a node without a config"""
49 self
.xmpp
['xep_0060'].create_node(
54 <iq type="set" id="1" to="pubsub.example.com">
55 <pubsub xmlns="http://jabber.org/protocol/pubsub">
56 <create node="princely_musings" />
61 def testCreateNodeConfig(self
):
62 """Test creating a node with a config"""
63 form
= self
.xmpp
['xep_0004'].stanza
.Form()
64 form
['type'] = 'submit'
65 form
.add_field(var
='pubsub#access_model', value
='whitelist')
67 self
.xmpp
['xep_0060'].create_node(
70 config
=form
, block
=False)
73 <iq type="set" id="1" to="pubsub.example.com">
74 <pubsub xmlns="http://jabber.org/protocol/pubsub">
75 <create node="princely_musings" />
77 <x xmlns="jabber:x:data" type="submit">
78 <field var="pubsub#access_model">
79 <value>whitelist</value>
81 <field var="FORM_TYPE">
82 <value>http://jabber.org/protocol/pubsub#node_config</value>
90 def testDeleteNode(self
):
91 """Test deleting a node"""
92 self
.xmpp
['xep_0060'].delete_node(
97 <iq type="set" to="pubsub.example.com" id="1">
98 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
99 <delete node="some_node" />
104 def testSubscribeCase1(self
):
106 Test subscribing to a node: Case 1:
107 No subscribee, default 'from' JID, bare JID
109 self
.xmpp
['xep_0060'].subscribe(
110 'pubsub.example.com',
114 <iq type="set" id="1" to="pubsub.example.com">
115 <pubsub xmlns="http://jabber.org/protocol/pubsub">
116 <subscribe node="somenode" jid="tester@localhost" />
121 def testSubscribeCase2(self
):
123 Test subscribing to a node: Case 2:
124 No subscribee, given 'from' JID, bare JID
126 self
.xmpp
['xep_0060'].subscribe(
127 'pubsub.example.com',
129 ifrom
='foo@comp.example.com/bar',
132 <iq type="set" id="1"
133 to="pubsub.example.com" from="foo@comp.example.com/bar">
134 <pubsub xmlns="http://jabber.org/protocol/pubsub">
135 <subscribe node="somenode" jid="foo@comp.example.com" />
140 def testSubscribeCase3(self
):
142 Test subscribing to a node: Case 3:
143 No subscribee, given 'from' JID, full JID
145 self
.xmpp
['xep_0060'].subscribe(
146 'pubsub.example.com',
148 ifrom
='foo@comp.example.com/bar',
152 <iq type="set" id="1"
153 to="pubsub.example.com" from="foo@comp.example.com/bar">
154 <pubsub xmlns="http://jabber.org/protocol/pubsub">
155 <subscribe node="somenode" jid="foo@comp.example.com/bar" />
160 def testSubscribeCase4(self
):
162 Test subscribing to a node: Case 4:
163 No subscribee, no 'from' JID, full JID
166 self
.stream_start(jid
='tester@localhost/full')
168 self
.xmpp
['xep_0060'].subscribe(
169 'pubsub.example.com',
174 <iq type="set" id="1"
175 to="pubsub.example.com">
176 <pubsub xmlns="http://jabber.org/protocol/pubsub">
177 <subscribe node="somenode" jid="tester@localhost/full" />
182 def testSubscribeCase5(self
):
184 Test subscribing to a node: Case 5:
187 self
.xmpp
['xep_0060'].subscribe(
188 'pubsub.example.com',
190 subscribee
='user@example.com/foo',
191 ifrom
='foo@comp.example.com/bar',
194 <iq type="set" id="1"
195 to="pubsub.example.com" from="foo@comp.example.com/bar">
196 <pubsub xmlns="http://jabber.org/protocol/pubsub">
197 <subscribe node="somenode" jid="user@example.com/foo" />
202 def testSubscribeWithOptions(self
):
203 """Test subscribing to a node, with options."""
204 opts
= self
.xmpp
['xep_0004'].make_form()
207 value
='http://jabber.org/protocol/pubsub#subscribe_options',
213 opts
['type'] = 'submit'
215 self
.xmpp
['xep_0060'].subscribe(
216 'pubsub.example.com',
221 <iq type="set" id="1" to="pubsub.example.com">
222 <pubsub xmlns="http://jabber.org/protocol/pubsub">
223 <subscribe node="somenode" jid="tester@localhost" />
225 <x xmlns="jabber:x:data" type="submit">
226 <field var="FORM_TYPE">
227 <value>http://jabber.org/protocol/pubsub#subscribe_options</value>
229 <field var="pubsub#digest">
238 def testUnsubscribeCase1(self
):
240 Test unsubscribing from a node: Case 1:
241 No subscribee, default 'from' JID, bare JID
243 self
.xmpp
['xep_0060'].unsubscribe(
244 'pubsub.example.com',
248 <iq type="set" id="1" to="pubsub.example.com">
249 <pubsub xmlns="http://jabber.org/protocol/pubsub">
250 <unsubscribe node="somenode" jid="tester@localhost" />
255 def testUnsubscribeCase2(self
):
257 Test unsubscribing from a node: Case 2:
258 No subscribee, given 'from' JID, bare JID
260 self
.xmpp
['xep_0060'].unsubscribe(
261 'pubsub.example.com',
263 ifrom
='foo@comp.example.com/bar',
266 <iq type="set" id="1"
267 to="pubsub.example.com" from="foo@comp.example.com/bar">
268 <pubsub xmlns="http://jabber.org/protocol/pubsub">
269 <unsubscribe node="somenode" jid="foo@comp.example.com" />
274 def testUnsubscribeCase3(self
):
276 Test unsubscribing from a node: Case 3:
277 No subscribee, given 'from' JID, full JID
279 self
.xmpp
['xep_0060'].unsubscribe(
280 'pubsub.example.com',
282 ifrom
='foo@comp.example.com/bar',
286 <iq type="set" id="1"
287 to="pubsub.example.com" from="foo@comp.example.com/bar">
288 <pubsub xmlns="http://jabber.org/protocol/pubsub">
289 <unsubscribe node="somenode" jid="foo@comp.example.com/bar" />
294 def testUnsubscribeCase4(self
):
296 Test unsubscribing from a node: Case 4:
297 No subscribee, no 'from' JID, full JID
300 self
.stream_start(jid
='tester@localhost/full')
302 self
.xmpp
['xep_0060'].unsubscribe(
303 'pubsub.example.com',
308 <iq type="set" id="1"
309 to="pubsub.example.com">
310 <pubsub xmlns="http://jabber.org/protocol/pubsub">
311 <unsubscribe node="somenode" jid="tester@localhost/full" />
316 def testUnsubscribeCase5(self
):
318 Test unsubscribing from a node: Case 5:
321 self
.xmpp
['xep_0060'].unsubscribe(
322 'pubsub.example.com',
324 subscribee
='user@example.com/foo',
325 ifrom
='foo@comp.example.com/bar',
328 <iq type="set" id="1"
329 to="pubsub.example.com" from="foo@comp.example.com/bar">
330 <pubsub xmlns="http://jabber.org/protocol/pubsub">
331 <unsubscribe node="somenode" jid="user@example.com/foo" />
336 def testGetDefaultNodeConfig(self
):
337 """Test retrieving the default node config for a pubsub service."""
338 self
.xmpp
['xep_0060'].get_node_config(
339 'pubsub.example.com',
342 <iq type="get" id="1" to="pubsub.example.com">
343 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
347 """, use_values
=False)
349 def testGetNodeConfig(self
):
350 """Test getting the config for a given node."""
351 self
.xmpp
['xep_0060'].get_node_config(
352 'pubsub.example.com',
356 <iq type="get" id="1" to="pubsub.example.com">
357 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
358 <configure node="somenode" />
361 """, use_values
=False)
363 def testSetNodeConfig(self
):
364 """Test setting the configuration for a node."""
365 form
= self
.xmpp
['xep_0004'].make_form()
366 form
.add_field(var
='FORM_TYPE', ftype
='hidden',
367 value
='http://jabber.org/protocol/pubsub#node_config')
368 form
.add_field(var
='pubsub#title', ftype
='text-single',
369 value
='This is awesome!')
370 form
['type'] = 'submit'
372 self
.xmpp
['xep_0060'].set_node_config(
373 'pubsub.example.com',
378 <iq type="set" id="1" to="pubsub.example.com">
379 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
380 <configure node="somenode">
381 <x xmlns="jabber:x:data" type="submit">
382 <field var="FORM_TYPE">
383 <value>http://jabber.org/protocol/pubsub#node_config</value>
385 <field var="pubsub#title">
386 <value>This is awesome!</value>
394 def testPublishNoItems(self
):
395 """Test publishing no items (in order to generate events)"""
396 self
.xmpp
['xep_0060'].publish(
397 'pubsub.example.com',
401 <iq type="set" id="1" to="pubsub.example.com">
402 <pubsub xmlns="http://jabber.org/protocol/pubsub">
403 <publish node="somenode" />
408 def testPublishSingle(self
):
409 """Test publishing a single item."""
410 payload
= AtomEntry()
411 payload
['title'] = 'Test'
413 register_stanza_plugin(self
.xmpp
['xep_0060'].stanza
.Item
, AtomEntry
)
415 self
.xmpp
['xep_0060'].publish(
416 'pubsub.example.com',
422 <iq type="set" id="1" to="pubsub.example.com">
423 <pubsub xmlns="http://jabber.org/protocol/pubsub">
424 <publish node="somenode">
426 <entry xmlns="http://www.w3.org/2005/Atom">
433 """, use_values
=False)
435 def testPublishSingleOptions(self
):
436 """Test publishing a single item, with options."""
437 payload
= AtomEntry()
438 payload
['title'] = 'Test'
440 register_stanza_plugin(self
.xmpp
['xep_0060'].stanza
.Item
, AtomEntry
)
442 options
= self
.xmpp
['xep_0004'].make_form()
443 options
.add_field(var
='FORM_TYPE', ftype
='hidden',
444 value
='http://jabber.org/protocol/pubsub#publish-options')
445 options
.add_field(var
='pubsub#access_model', ftype
='text-single',
447 options
['type'] = 'submit'
449 self
.xmpp
['xep_0060'].publish(
450 'pubsub.example.com',
457 <iq type="set" id="1" to="pubsub.example.com">
458 <pubsub xmlns="http://jabber.org/protocol/pubsub">
459 <publish node="somenode">
461 <entry xmlns="http://www.w3.org/2005/Atom">
467 <x xmlns="jabber:x:data" type="submit">
468 <field var="FORM_TYPE">
469 <value>http://jabber.org/protocol/pubsub#publish-options</value>
471 <field var="pubsub#access_model">
472 <value>presence</value>
478 """, use_values
=False)
480 def testRetract(self
):
481 """Test deleting an item."""
482 self
.xmpp
['xep_0060'].retract(
483 'pubsub.example.com',
489 <iq type="set" id="1" to="pubsub.example.com">
490 <pubsub xmlns="http://jabber.org/protocol/pubsub">
491 <retract node="somenode" notify="true">
498 def testRetract(self
):
499 """Test deleting an item."""
500 self
.xmpp
['xep_0060'].retract(
501 'pubsub.example.com',
506 <iq type="set" id="1" to="pubsub.example.com">
507 <pubsub xmlns="http://jabber.org/protocol/pubsub">
508 <retract node="somenode">
516 """Test removing all items from a node."""
517 self
.xmpp
['xep_0060'].purge(
518 'pubsub.example.com',
522 <iq type="set" id="1" to="pubsub.example.com">
523 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
524 <purge node="somenode" />
529 def testGetItem(self
):
530 """Test retrieving a single item."""
531 self
.xmpp
['xep_0060'].get_item(
532 'pubsub.example.com',
537 <iq type="get" id="1" to="pubsub.example.com">
538 <pubsub xmlns="http://jabber.org/protocol/pubsub">
539 <items node="somenode">
546 def testGetLatestItems(self
):
547 """Test retrieving the most recent N items."""
548 self
.xmpp
['xep_0060'].get_items(
549 'pubsub.example.com',
554 <iq type="get" id="1" to="pubsub.example.com">
555 <pubsub xmlns="http://jabber.org/protocol/pubsub">
556 <items node="somenode" max_items="3" />
561 def testGetAllItems(self
):
562 """Test retrieving all items."""
563 self
.xmpp
['xep_0060'].get_items(
564 'pubsub.example.com',
568 <iq type="get" id="1" to="pubsub.example.com">
569 <pubsub xmlns="http://jabber.org/protocol/pubsub">
570 <items node="somenode" />
575 def testGetSpecificItems(self
):
576 """Test retrieving a specific set of items."""
577 self
.xmpp
['xep_0060'].get_items(
578 'pubsub.example.com',
580 item_ids
=['A', 'B', 'C'],
583 <iq type="get" id="1" to="pubsub.example.com">
584 <pubsub xmlns="http://jabber.org/protocol/pubsub">
585 <items node="somenode">
594 def testGetSubscriptionGlobalDefaultOptions(self
):
595 """Test getting the subscription options for a node/JID."""
596 self
.xmpp
['xep_0060'].get_subscription_options(
597 'pubsub.example.com',
600 <iq type="get" id="1" to="pubsub.example.com">
601 <pubsub xmlns="http://jabber.org/protocol/pubsub">
605 """, use_values
=False)
607 def testGetSubscriptionNodeDefaultOptions(self
):
608 """Test getting the subscription options for a node/JID."""
609 self
.xmpp
['xep_0060'].get_subscription_options(
610 'pubsub.example.com',
614 <iq type="get" id="1" to="pubsub.example.com">
615 <pubsub xmlns="http://jabber.org/protocol/pubsub">
616 <default node="somenode" />
619 """, use_values
=False)
621 def testGetSubscriptionOptions(self
):
622 """Test getting the subscription options for a node/JID."""
623 self
.xmpp
['xep_0060'].get_subscription_options(
624 'pubsub.example.com',
629 <iq type="get" id="1" to="pubsub.example.com">
630 <pubsub xmlns="http://jabber.org/protocol/pubsub">
631 <options node="somenode" jid="tester@localhost" />
634 """, use_values
=False)
636 def testSetSubscriptionOptions(self
):
637 """Test setting the subscription options for a node/JID."""
638 opts
= self
.xmpp
['xep_0004'].make_form()
641 value
='http://jabber.org/protocol/pubsub#subscribe_options',
647 opts
['type'] = 'submit'
649 self
.xmpp
['xep_0060'].set_subscription_options(
650 'pubsub.example.com',
656 <iq type="get" id="1" to="pubsub.example.com">
657 <pubsub xmlns="http://jabber.org/protocol/pubsub">
658 <options node="somenode" jid="tester@localhost">
659 <x xmlns="jabber:x:data" type="submit">
660 <field var="FORM_TYPE">
661 <value>http://jabber.org/protocol/pubsub#subscribe_options</value>
663 <field var="pubsub#digest">
672 def testGetNodeSubscriptions(self
):
673 """Test retrieving all subscriptions for a node."""
674 self
.xmpp
['xep_0060'].get_node_subscriptions(
675 'pubsub.example.com',
679 <iq type="get" id="1" to="pubsub.example.com">
680 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
681 <subscriptions node="somenode" />
686 def testGetSubscriptions(self
):
687 """Test retrieving a users's subscriptions."""
688 self
.xmpp
['xep_0060'].get_subscriptions(
689 'pubsub.example.com',
692 <iq type="get" id="1" to="pubsub.example.com">
693 <pubsub xmlns="http://jabber.org/protocol/pubsub">
699 def testGetSubscriptionsForNode(self
):
700 """Test retrieving a users's subscriptions for a given node."""
701 self
.xmpp
['xep_0060'].get_subscriptions(
702 'pubsub.example.com',
706 <iq type="get" id="1" to="pubsub.example.com">
707 <pubsub xmlns="http://jabber.org/protocol/pubsub">
708 <subscriptions node="somenode" />
713 def testGetAffiliations(self
):
714 """Test retrieving a users's affiliations."""
715 self
.xmpp
['xep_0060'].get_affiliations(
716 'pubsub.example.com',
719 <iq type="get" id="1" to="pubsub.example.com">
720 <pubsub xmlns="http://jabber.org/protocol/pubsub">
726 def testGetAffiliatinssForNode(self
):
727 """Test retrieving a users's affiliations for a given node."""
728 self
.xmpp
['xep_0060'].get_affiliations(
729 'pubsub.example.com',
733 <iq type="get" id="1" to="pubsub.example.com">
734 <pubsub xmlns="http://jabber.org/protocol/pubsub">
735 <affiliations node="somenode" />
740 def testGetNodeAffiliations(self
):
741 """Test getting the affiliations for a node."""
742 self
.xmpp
['xep_0060'].get_node_affiliations(
743 'pubsub.example.com',
747 <iq type="get" id="1" to="pubsub.example.com">
748 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
749 <affiliations node="somenode" />
754 def testModifySubscriptions(self
):
755 """Test owner modifying node subscriptions."""
756 self
.xmpp
['xep_0060'].modify_subscriptions(
757 'pubsub.example.com',
759 subscriptions
=[('user@example.com', 'subscribed'),
760 ('foo@example.net', 'none')],
763 <iq type="set" id="1" to="pubsub.example.com">
764 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
765 <subscriptions node="somenode">
766 <subscription jid="user@example.com" subscription="subscribed" />
767 <subscription jid="foo@example.net" subscription="none" />
773 def testModifyAffiliations(self
):
774 """Test owner modifying node affiliations."""
775 self
.xmpp
['xep_0060'].modify_affiliations(
776 'pubsub.example.com',
778 affiliations
=[('user@example.com', 'publisher'),
779 ('foo@example.net', 'none')],
782 <iq type="set" id="1" to="pubsub.example.com">
783 <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
784 <affiliations node="somenode">
785 <affiliation jid="user@example.com" affiliation="publisher" />
786 <affiliation jid="foo@example.net" affiliation="none" />
793 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestStreamPubsub
)