Add ability for a user to get retrieve subscriptions, with tests.

This commit is contained in:
Lance Stout 2011-09-01 11:19:25 -07:00
parent 993829b23f
commit ec01e45ed1
3 changed files with 36 additions and 2 deletions

View file

@ -171,6 +171,12 @@ class xep_0060(base_plugin):
iq['pubsub']['unsubscribe']['subid'] = subid
return iq.send(block=block, callback=callback, timeout=timeout)
def get_subscriptions(self, jid, node=None, ifrom=None, block=True,
callback=None, timeout=None):
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
iq['pubsub']['subscriptions']['node'] = node
return iq.send(block=block, callback=callback, timeout=timeout)
def get_subscription_options(self, jid, node, user_jid, ifrom=None,
block=True, callback=None, timeout=None):
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')

View file

@ -65,7 +65,7 @@ class Subscriptions(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'subscriptions'
plugin_attrib = 'subscriptions'
interfaces = set(tuple())
interfaces = set(('node',))
plugin_attrib_map = {}
plugin_tag_map = {}
subitem = (Subscription,)

View file

@ -626,7 +626,7 @@ class TestStreamPubsub(SleekTest):
""")
def testGetNodeSubscriptions(self):
"""Test retrieving the subscriptions for a node."""
"""Test retrieving all subscriptions for a node."""
self.xmpp['xep_0060'].get_node_subscriptions(
'pubsub.example.com',
'somenode',
@ -639,4 +639,32 @@ class TestStreamPubsub(SleekTest):
</iq>
""")
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>
""")
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPubsub)