From 462b375c8f9ff22cdd4fe282dd90b0a5154a938c Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 1 Sep 2011 12:08:35 -0700 Subject: [PATCH] Owners can modify subscriptions/affiliations. With tests. 94% coverage for the main pubsub plugin! (91% including stanzas) --- sleekxmpp/plugins/xep_0060/pubsub.py | 8 +-- .../plugins/xep_0060/stanza/pubsub_owner.py | 10 ++-- tests/test_stream_xep_0060.py | 52 +++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/sleekxmpp/plugins/xep_0060/pubsub.py b/sleekxmpp/plugins/xep_0060/pubsub.py index a5db137..5a9fe70 100644 --- a/sleekxmpp/plugins/xep_0060/pubsub.py +++ b/sleekxmpp/plugins/xep_0060/pubsub.py @@ -400,8 +400,8 @@ class xep_0060(base_plugin): affiliations = [] for jid, affiliation in affiliations: - aff = stanza.pubsub.Affiliation() - aff['jid'] = user_jid + aff = self.stanza.OwnerAffiliation() + aff['jid'] = jid aff['affiliation'] = affiliation iq['pubsub_owner']['affiliations'].append(aff) @@ -416,8 +416,8 @@ class xep_0060(base_plugin): subscriptions = [] for jid, subscription in subscriptions: - sub = self.stanza.Subscription() - sub['jid'] = user_jid + sub = self.stanza.OwnerSubscription() + sub['jid'] = jid sub['subscription'] = subscription iq['pubsub_owner']['subscriptions'].append(sub) diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub_owner.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub_owner.py index fd8ec1f..1fdfb73 100644 --- a/sleekxmpp/plugins/xep_0060/stanza/pubsub_owner.py +++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub_owner.py @@ -41,7 +41,7 @@ registerStanzaPlugin(DefaultConfig, xep_0004.Form) class OwnerAffiliations(Affiliations): namespace = 'http://jabber.org/protocol/pubsub#owner' - interfaces = set(('node')) + interfaces = set(('node',)) plugin_attrib_map = {} plugin_tag_map = {} @@ -49,7 +49,6 @@ class OwnerAffiliations(Affiliations): if not isinstance(affiliation, OwnerAffiliation): raise TypeError self.xml.append(affiliation.xml) - return self.affiliations.append(affiliation) registerStanzaPlugin(PubsubOwner, OwnerAffiliations) @@ -59,6 +58,8 @@ class OwnerAffiliation(Affiliation): plugin_attrib_map = {} plugin_tag_map = {} +registerStanzaPlugin(OwnerAffiliations, OwnerAffiliation, iterable=True) + class OwnerConfigure(Configure): name = 'configure' plugin_attrib = 'configure' @@ -126,7 +127,6 @@ class OwnerSubscriptions(Subscriptions): if not isinstance(subscription, OwnerSubscription): raise TypeError self.xml.append(subscription.xml) - return self.subscriptions.append(subscription) registerStanzaPlugin(PubsubOwner, OwnerSubscriptions) @@ -142,4 +142,6 @@ class OwnerSubscription(ElementBase): self._setAttr('jid', str(value)) def getJid(self): - return JID(self._getAttr('from')) + return JID(self._getAttr('jid')) + +registerStanzaPlugin(OwnerSubscriptions, OwnerSubscription, iterable=True) diff --git a/tests/test_stream_xep_0060.py b/tests/test_stream_xep_0060.py index b90359f..7839d99 100644 --- a/tests/test_stream_xep_0060.py +++ b/tests/test_stream_xep_0060.py @@ -693,5 +693,57 @@ class TestStreamPubsub(SleekTest): """) + 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(""" + + + + + + """) + + 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(""" + + + + + + + + + """) + + 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(""" + + + + + + + + + """) + suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPubsub)