2011-08-26 19:14:57 +00:00
|
|
|
import threading
|
|
|
|
|
2013-07-26 11:02:26 +00:00
|
|
|
import unittest
|
2014-07-17 12:19:04 +00:00
|
|
|
from slixmpp.test import SlixTest
|
|
|
|
from slixmpp.stanza.atom import AtomEntry
|
|
|
|
from slixmpp.xmlstream import register_stanza_plugin
|
2011-08-26 19:14:57 +00:00
|
|
|
|
|
|
|
|
2014-07-17 12:19:04 +00:00
|
|
|
class TestStreamPubsub(SlixTest):
|
2011-08-26 19:14:57 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Test using the XEP-0030 plugin.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.stream_start()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.stream_close()
|
|
|
|
|
|
|
|
def testCreateInstantNode(self):
|
|
|
|
"""Test creating an instant node"""
|
|
|
|
t = threading.Thread(name='create_node',
|
|
|
|
target=self.xmpp['xep_0060'].create_node,
|
|
|
|
args=('pubsub.example.com', None))
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<create />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="result" id="1"
|
|
|
|
to="tester@localhost" from="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<create node="25e3d37dabbab9541f7523321421edc5bfeb2dae" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
t.join()
|
|
|
|
|
|
|
|
def testCreateNodeNoConfig(self):
|
|
|
|
"""Test creating a node without a config"""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].create_node(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'princely_musings',
|
|
|
|
block=False)
|
2011-08-26 19:14:57 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<create node="princely_musings" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testCreateNodeConfig(self):
|
|
|
|
"""Test creating a node with a config"""
|
|
|
|
form = self.xmpp['xep_0004'].stanza.Form()
|
|
|
|
form['type'] = 'submit'
|
|
|
|
form.add_field(var='pubsub#access_model', value='whitelist')
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].create_node(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'princely_musings',
|
|
|
|
config=form, block=False)
|
2011-08-26 19:14:57 +00:00
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<create node="princely_musings" />
|
|
|
|
<configure>
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
|
|
|
<field var="pubsub#access_model">
|
|
|
|
<value>whitelist</value>
|
|
|
|
</field>
|
|
|
|
<field var="FORM_TYPE">
|
|
|
|
<value>http://jabber.org/protocol/pubsub#node_config</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</configure>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-08-31 04:57:11 +00:00
|
|
|
def testDeleteNode(self):
|
|
|
|
"""Test deleting a node"""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].delete_node(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'some_node',
|
|
|
|
block=False)
|
2011-08-31 04:57:11 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" to="pubsub.example.com" id="1">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<delete node="some_node" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testSubscribeCase1(self):
|
|
|
|
"""
|
|
|
|
Test subscribing to a node: Case 1:
|
|
|
|
No subscribee, default 'from' JID, bare JID
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].subscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscribe node="somenode" jid="tester@localhost" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
2011-08-31 04:57:11 +00:00
|
|
|
""")
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testSubscribeCase2(self):
|
|
|
|
"""
|
|
|
|
Test subscribing to a node: Case 2:
|
|
|
|
No subscribee, given 'from' JID, bare JID
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].subscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
ifrom='foo@comp.example.com/bar',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com" from="foo@comp.example.com/bar">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscribe node="somenode" jid="foo@comp.example.com" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testSubscribeCase3(self):
|
|
|
|
"""
|
|
|
|
Test subscribing to a node: Case 3:
|
|
|
|
No subscribee, given 'from' JID, full JID
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].subscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
ifrom='foo@comp.example.com/bar',
|
|
|
|
bare=False,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com" from="foo@comp.example.com/bar">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscribe node="somenode" jid="foo@comp.example.com/bar" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 04:57:11 +00:00
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testSubscribeCase4(self):
|
|
|
|
"""
|
|
|
|
Test subscribing to a node: Case 4:
|
|
|
|
No subscribee, no 'from' JID, full JID
|
|
|
|
"""
|
|
|
|
self.stream_close()
|
|
|
|
self.stream_start(jid='tester@localhost/full')
|
|
|
|
|
|
|
|
self.xmpp['xep_0060'].subscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
bare=False,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscribe node="somenode" jid="tester@localhost/full" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testSubscribeCase5(self):
|
|
|
|
"""
|
|
|
|
Test subscribing to a node: Case 5:
|
|
|
|
Subscribee given
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].subscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
subscribee='user@example.com/foo',
|
|
|
|
ifrom='foo@comp.example.com/bar',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com" from="foo@comp.example.com/bar">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscribe node="somenode" jid="user@example.com/foo" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 05:27:02 +00:00
|
|
|
|
|
|
|
def testSubscribeWithOptions(self):
|
2011-09-01 17:44:14 +00:00
|
|
|
"""Test subscribing to a node, with options."""
|
|
|
|
opts = self.xmpp['xep_0004'].make_form()
|
|
|
|
opts.add_field(
|
|
|
|
var='FORM_TYPE',
|
|
|
|
value='http://jabber.org/protocol/pubsub#subscribe_options',
|
|
|
|
ftype='hidden')
|
|
|
|
opts.add_field(
|
|
|
|
var='pubsub#digest',
|
|
|
|
value=False,
|
|
|
|
ftype='boolean')
|
|
|
|
opts['type'] = 'submit'
|
|
|
|
|
|
|
|
self.xmpp['xep_0060'].subscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
options=opts,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscribe node="somenode" jid="tester@localhost" />
|
|
|
|
<options>
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
|
|
|
<field var="FORM_TYPE">
|
|
|
|
<value>http://jabber.org/protocol/pubsub#subscribe_options</value>
|
|
|
|
</field>
|
|
|
|
<field var="pubsub#digest">
|
|
|
|
<value>0</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</options>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 05:27:02 +00:00
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testUnsubscribeCase1(self):
|
|
|
|
"""
|
|
|
|
Test unsubscribing from a node: Case 1:
|
|
|
|
No subscribee, default 'from' JID, bare JID
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].unsubscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<unsubscribe node="somenode" jid="tester@localhost" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 17:43:33 +00:00
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testUnsubscribeCase2(self):
|
|
|
|
"""
|
|
|
|
Test unsubscribing from a node: Case 2:
|
|
|
|
No subscribee, given 'from' JID, bare JID
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].unsubscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
ifrom='foo@comp.example.com/bar',
|
|
|
|
block=False)
|
2011-08-31 17:43:33 +00:00
|
|
|
self.send("""
|
2011-09-01 04:52:17 +00:00
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com" from="foo@comp.example.com/bar">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<unsubscribe node="somenode" jid="foo@comp.example.com" />
|
2011-08-31 17:43:33 +00:00
|
|
|
</pubsub>
|
|
|
|
</iq>
|
2011-09-01 04:52:17 +00:00
|
|
|
""")
|
2011-08-31 17:43:33 +00:00
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testUnsubscribeCase3(self):
|
|
|
|
"""
|
|
|
|
Test unsubscribing from a node: Case 3:
|
|
|
|
No subscribee, given 'from' JID, full JID
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].unsubscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
ifrom='foo@comp.example.com/bar',
|
|
|
|
bare=False,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com" from="foo@comp.example.com/bar">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<unsubscribe node="somenode" jid="foo@comp.example.com/bar" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
2011-08-31 17:43:33 +00:00
|
|
|
""")
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
def testUnsubscribeCase4(self):
|
|
|
|
"""
|
|
|
|
Test unsubscribing from a node: Case 4:
|
|
|
|
No subscribee, no 'from' JID, full JID
|
|
|
|
"""
|
|
|
|
self.stream_close()
|
|
|
|
self.stream_start(jid='tester@localhost/full')
|
|
|
|
|
|
|
|
self.xmpp['xep_0060'].unsubscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
bare=False,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<unsubscribe node="somenode" jid="tester@localhost/full" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testUnsubscribeCase5(self):
|
|
|
|
"""
|
|
|
|
Test unsubscribing from a node: Case 5:
|
|
|
|
Subscribee given
|
|
|
|
"""
|
|
|
|
self.xmpp['xep_0060'].unsubscribe(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
subscribee='user@example.com/foo',
|
|
|
|
ifrom='foo@comp.example.com/bar',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1"
|
|
|
|
to="pubsub.example.com" from="foo@comp.example.com/bar">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<unsubscribe node="somenode" jid="user@example.com/foo" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 17:43:33 +00:00
|
|
|
|
|
|
|
def testGetDefaultNodeConfig(self):
|
2011-08-31 21:05:29 +00:00
|
|
|
"""Test retrieving the default node config for a pubsub service."""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].get_node_config(
|
|
|
|
'pubsub.example.com',
|
|
|
|
block=False)
|
2011-08-31 21:05:29 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<default />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
def testGetNodeConfig(self):
|
|
|
|
"""Test getting the config for a given node."""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].get_node_config(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
2011-08-31 17:43:33 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
2011-08-31 21:05:29 +00:00
|
|
|
<configure node="somenode" />
|
2011-08-31 17:43:33 +00:00
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
2011-08-31 21:05:29 +00:00
|
|
|
def testSetNodeConfig(self):
|
|
|
|
"""Test setting the configuration for a node."""
|
|
|
|
form = self.xmpp['xep_0004'].make_form()
|
|
|
|
form.add_field(var='FORM_TYPE', ftype='hidden',
|
|
|
|
value='http://jabber.org/protocol/pubsub#node_config')
|
|
|
|
form.add_field(var='pubsub#title', ftype='text-single',
|
|
|
|
value='This is awesome!')
|
|
|
|
form['type'] = 'submit'
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].set_node_config(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
form,
|
|
|
|
block=False)
|
2011-08-31 21:05:29 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<configure node="somenode">
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
|
|
|
<field var="FORM_TYPE">
|
|
|
|
<value>http://jabber.org/protocol/pubsub#node_config</value>
|
|
|
|
</field>
|
|
|
|
<field var="pubsub#title">
|
|
|
|
<value>This is awesome!</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</configure>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 06:48:22 +00:00
|
|
|
def testPublishNoItems(self):
|
|
|
|
"""Test publishing no items (in order to generate events)"""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].publish(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
2011-08-31 21:31:20 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
2011-09-01 06:48:22 +00:00
|
|
|
<publish node="somenode" />
|
2011-08-31 21:31:20 +00:00
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 06:48:22 +00:00
|
|
|
def testPublishSingle(self):
|
|
|
|
"""Test publishing a single item."""
|
2011-08-31 21:55:37 +00:00
|
|
|
payload = AtomEntry()
|
|
|
|
payload['title'] = 'Test'
|
|
|
|
|
|
|
|
register_stanza_plugin(self.xmpp['xep_0060'].stanza.Item, AtomEntry)
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].publish(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
2011-09-01 06:48:22 +00:00
|
|
|
id='id42',
|
2011-09-01 04:52:17 +00:00
|
|
|
payload=payload,
|
|
|
|
block=False)
|
2011-08-31 21:55:37 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<publish node="somenode">
|
2011-09-01 06:48:22 +00:00
|
|
|
<item id="id42">
|
2011-08-31 21:55:37 +00:00
|
|
|
<entry xmlns="http://www.w3.org/2005/Atom">
|
|
|
|
<title>Test</title>
|
|
|
|
</entry>
|
|
|
|
</item>
|
|
|
|
</publish>
|
2011-08-31 22:04:46 +00:00
|
|
|
</pubsub>
|
|
|
|
</iq>
|
2013-03-11 23:41:44 +00:00
|
|
|
""", use_values=False)
|
2011-08-31 22:04:46 +00:00
|
|
|
|
2011-09-01 06:48:22 +00:00
|
|
|
def testPublishSingleOptions(self):
|
|
|
|
"""Test publishing a single item, with options."""
|
|
|
|
payload = AtomEntry()
|
|
|
|
payload['title'] = 'Test'
|
2011-08-31 22:04:46 +00:00
|
|
|
|
|
|
|
register_stanza_plugin(self.xmpp['xep_0060'].stanza.Item, AtomEntry)
|
|
|
|
|
|
|
|
options = self.xmpp['xep_0004'].make_form()
|
|
|
|
options.add_field(var='FORM_TYPE', ftype='hidden',
|
|
|
|
value='http://jabber.org/protocol/pubsub#publish-options')
|
|
|
|
options.add_field(var='pubsub#access_model', ftype='text-single',
|
|
|
|
value='presence')
|
|
|
|
options['type'] = 'submit'
|
|
|
|
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].publish(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
2011-09-01 06:48:22 +00:00
|
|
|
id='ID42',
|
|
|
|
payload=payload,
|
2011-09-01 04:52:17 +00:00
|
|
|
options=options,
|
|
|
|
block=False)
|
2011-08-31 22:04:46 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<publish node="somenode">
|
2011-09-01 06:48:22 +00:00
|
|
|
<item id="ID42">
|
2011-08-31 22:04:46 +00:00
|
|
|
<entry xmlns="http://www.w3.org/2005/Atom">
|
2011-09-01 06:48:22 +00:00
|
|
|
<title>Test</title>
|
2011-08-31 22:04:46 +00:00
|
|
|
</entry>
|
|
|
|
</item>
|
|
|
|
</publish>
|
|
|
|
<publish-options>
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
|
|
|
<field var="FORM_TYPE">
|
|
|
|
<value>http://jabber.org/protocol/pubsub#publish-options</value>
|
|
|
|
</field>
|
|
|
|
<field var="pubsub#access_model">
|
|
|
|
<value>presence</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</publish-options>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
2011-09-01 20:36:11 +00:00
|
|
|
def testRetract(self):
|
|
|
|
"""Test deleting an item."""
|
|
|
|
self.xmpp['xep_0060'].retract(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
'ID1',
|
|
|
|
notify=True,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<retract node="somenode" notify="true">
|
|
|
|
<item id="ID1" />
|
|
|
|
</retract>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-08-31 21:05:29 +00:00
|
|
|
def testRetract(self):
|
|
|
|
"""Test deleting an item."""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].retract(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
'ID1',
|
|
|
|
block=False)
|
2011-08-31 23:03:32 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<retract node="somenode">
|
|
|
|
<item id="ID1" />
|
|
|
|
</retract>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
2011-09-01 07:50:45 +00:00
|
|
|
""")
|
2011-08-31 23:03:32 +00:00
|
|
|
|
2011-08-31 21:05:29 +00:00
|
|
|
def testPurge(self):
|
|
|
|
"""Test removing all items from a node."""
|
2011-09-01 04:52:17 +00:00
|
|
|
self.xmpp['xep_0060'].purge(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
2011-09-01 04:09:25 +00:00
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<purge node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-08-31 21:05:29 +00:00
|
|
|
def testGetItem(self):
|
|
|
|
"""Test retrieving a single item."""
|
2011-09-01 16:27:10 +00:00
|
|
|
self.xmpp['xep_0060'].get_item(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
'id42',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<items node="somenode">
|
|
|
|
<item id="id42" />
|
|
|
|
</items>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 21:05:29 +00:00
|
|
|
|
|
|
|
def testGetLatestItems(self):
|
|
|
|
"""Test retrieving the most recent N items."""
|
2011-09-01 16:27:10 +00:00
|
|
|
self.xmpp['xep_0060'].get_items(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
max_items=3,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<items node="somenode" max_items="3" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 21:05:29 +00:00
|
|
|
|
|
|
|
def testGetAllItems(self):
|
|
|
|
"""Test retrieving all items."""
|
2011-09-01 16:27:10 +00:00
|
|
|
self.xmpp['xep_0060'].get_items(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<items node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 21:05:29 +00:00
|
|
|
|
|
|
|
def testGetSpecificItems(self):
|
|
|
|
"""Test retrieving a specific set of items."""
|
2011-09-01 16:27:10 +00:00
|
|
|
self.xmpp['xep_0060'].get_items(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
item_ids=['A', 'B', 'C'],
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<items node="somenode">
|
|
|
|
<item id="A" />
|
|
|
|
<item id="B" />
|
|
|
|
<item id="C" />
|
|
|
|
</items>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 20:25:35 +00:00
|
|
|
def testGetSubscriptionGlobalDefaultOptions(self):
|
|
|
|
"""Test getting the subscription options for a node/JID."""
|
|
|
|
self.xmpp['xep_0060'].get_subscription_options(
|
|
|
|
'pubsub.example.com',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<default />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
def testGetSubscriptionNodeDefaultOptions(self):
|
|
|
|
"""Test getting the subscription options for a node/JID."""
|
|
|
|
self.xmpp['xep_0060'].get_subscription_options(
|
|
|
|
'pubsub.example.com',
|
|
|
|
node='somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<default node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
2011-09-01 17:44:14 +00:00
|
|
|
def testGetSubscriptionOptions(self):
|
|
|
|
"""Test getting the subscription options for a node/JID."""
|
|
|
|
self.xmpp['xep_0060'].get_subscription_options(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
'tester@localhost',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<options node="somenode" jid="tester@localhost" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
def testSetSubscriptionOptions(self):
|
|
|
|
"""Test setting the subscription options for a node/JID."""
|
|
|
|
opts = self.xmpp['xep_0004'].make_form()
|
|
|
|
opts.add_field(
|
|
|
|
var='FORM_TYPE',
|
|
|
|
value='http://jabber.org/protocol/pubsub#subscribe_options',
|
|
|
|
ftype='hidden')
|
|
|
|
opts.add_field(
|
|
|
|
var='pubsub#digest',
|
|
|
|
value=False,
|
|
|
|
ftype='boolean')
|
|
|
|
opts['type'] = 'submit'
|
|
|
|
|
|
|
|
self.xmpp['xep_0060'].set_subscription_options(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
'tester@localhost',
|
|
|
|
opts,
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<options node="somenode" jid="tester@localhost">
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
|
|
|
<field var="FORM_TYPE">
|
|
|
|
<value>http://jabber.org/protocol/pubsub#subscribe_options</value>
|
|
|
|
</field>
|
|
|
|
<field var="pubsub#digest">
|
|
|
|
<value>0</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</options>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-31 21:05:29 +00:00
|
|
|
|
2011-09-01 17:44:14 +00:00
|
|
|
def testGetNodeSubscriptions(self):
|
2011-09-01 18:19:25 +00:00
|
|
|
"""Test retrieving all subscriptions for a node."""
|
2011-09-01 17:44:14 +00:00
|
|
|
self.xmpp['xep_0060'].get_node_subscriptions(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<subscriptions node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
2011-08-26 19:14:57 +00:00
|
|
|
|
2011-09-01 18:19:25 +00:00
|
|
|
def testGetSubscriptions(self):
|
|
|
|
"""Test retrieving a users's subscriptions."""
|
|
|
|
self.xmpp['xep_0060'].get_subscriptions(
|
|
|
|
'pubsub.example.com',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscriptions />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testGetSubscriptionsForNode(self):
|
|
|
|
"""Test retrieving a users's subscriptions for a given node."""
|
|
|
|
self.xmpp['xep_0060'].get_subscriptions(
|
|
|
|
'pubsub.example.com',
|
|
|
|
node='somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscriptions node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 18:30:55 +00:00
|
|
|
def testGetAffiliations(self):
|
|
|
|
"""Test retrieving a users's affiliations."""
|
|
|
|
self.xmpp['xep_0060'].get_affiliations(
|
|
|
|
'pubsub.example.com',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<affiliations />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testGetAffiliatinssForNode(self):
|
|
|
|
"""Test retrieving a users's affiliations for a given node."""
|
|
|
|
self.xmpp['xep_0060'].get_affiliations(
|
|
|
|
'pubsub.example.com',
|
|
|
|
node='somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<affiliations node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 19:08:35 +00:00
|
|
|
def testGetNodeAffiliations(self):
|
|
|
|
"""Test getting the affiliations for a node."""
|
|
|
|
self.xmpp['xep_0060'].get_node_affiliations(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<affiliations node="somenode" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testModifySubscriptions(self):
|
|
|
|
"""Test owner modifying node subscriptions."""
|
|
|
|
self.xmpp['xep_0060'].modify_subscriptions(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
subscriptions=[('user@example.com', 'subscribed'),
|
|
|
|
('foo@example.net', 'none')],
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<subscriptions node="somenode">
|
|
|
|
<subscription jid="user@example.com" subscription="subscribed" />
|
|
|
|
<subscription jid="foo@example.net" subscription="none" />
|
|
|
|
</subscriptions>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testModifyAffiliations(self):
|
|
|
|
"""Test owner modifying node affiliations."""
|
|
|
|
self.xmpp['xep_0060'].modify_affiliations(
|
|
|
|
'pubsub.example.com',
|
|
|
|
'somenode',
|
|
|
|
affiliations=[('user@example.com', 'publisher'),
|
|
|
|
('foo@example.net', 'none')],
|
|
|
|
block=False)
|
|
|
|
self.send("""
|
|
|
|
<iq type="set" id="1" to="pubsub.example.com">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<affiliations node="somenode">
|
|
|
|
<affiliation jid="user@example.com" affiliation="publisher" />
|
|
|
|
<affiliation jid="foo@example.net" affiliation="none" />
|
|
|
|
</affiliations>
|
|
|
|
</pubsub>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2011-09-01 18:19:25 +00:00
|
|
|
|
2011-08-26 19:14:57 +00:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPubsub)
|