diff options
-rw-r--r-- | sleekxmpp/plugins/xep_0060/pubsub.py | 6 | ||||
-rw-r--r-- | sleekxmpp/plugins/xep_0060/stanza/pubsub.py | 2 | ||||
-rw-r--r-- | tests/test_stream_xep_0060.py | 30 |
3 files changed, 36 insertions, 2 deletions
diff --git a/sleekxmpp/plugins/xep_0060/pubsub.py b/sleekxmpp/plugins/xep_0060/pubsub.py index 788d3397..990e8241 100644 --- a/sleekxmpp/plugins/xep_0060/pubsub.py +++ b/sleekxmpp/plugins/xep_0060/pubsub.py @@ -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') diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub.py index d62fc661..0cbb7388 100644 --- a/sleekxmpp/plugins/xep_0060/stanza/pubsub.py +++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub.py @@ -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,) diff --git a/tests/test_stream_xep_0060.py b/tests/test_stream_xep_0060.py index 9ba01468..1ace0f96 100644 --- a/tests/test_stream_xep_0060.py +++ b/tests/test_stream_xep_0060.py @@ -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) |