Owners can modify subscriptions/affiliations. With tests.

94% coverage for the main pubsub plugin! (91% including stanzas)
This commit is contained in:
Lance Stout 2011-09-01 12:08:35 -07:00
parent afbd506cfc
commit 462b375c8f
3 changed files with 62 additions and 8 deletions

View file

@ -400,8 +400,8 @@ class xep_0060(base_plugin):
affiliations = [] affiliations = []
for jid, affiliation in affiliations: for jid, affiliation in affiliations:
aff = stanza.pubsub.Affiliation() aff = self.stanza.OwnerAffiliation()
aff['jid'] = user_jid aff['jid'] = jid
aff['affiliation'] = affiliation aff['affiliation'] = affiliation
iq['pubsub_owner']['affiliations'].append(aff) iq['pubsub_owner']['affiliations'].append(aff)
@ -416,8 +416,8 @@ class xep_0060(base_plugin):
subscriptions = [] subscriptions = []
for jid, subscription in subscriptions: for jid, subscription in subscriptions:
sub = self.stanza.Subscription() sub = self.stanza.OwnerSubscription()
sub['jid'] = user_jid sub['jid'] = jid
sub['subscription'] = subscription sub['subscription'] = subscription
iq['pubsub_owner']['subscriptions'].append(sub) iq['pubsub_owner']['subscriptions'].append(sub)

View file

@ -41,7 +41,7 @@ registerStanzaPlugin(DefaultConfig, xep_0004.Form)
class OwnerAffiliations(Affiliations): class OwnerAffiliations(Affiliations):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
interfaces = set(('node')) interfaces = set(('node',))
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
@ -49,7 +49,6 @@ class OwnerAffiliations(Affiliations):
if not isinstance(affiliation, OwnerAffiliation): if not isinstance(affiliation, OwnerAffiliation):
raise TypeError raise TypeError
self.xml.append(affiliation.xml) self.xml.append(affiliation.xml)
return self.affiliations.append(affiliation)
registerStanzaPlugin(PubsubOwner, OwnerAffiliations) registerStanzaPlugin(PubsubOwner, OwnerAffiliations)
@ -59,6 +58,8 @@ class OwnerAffiliation(Affiliation):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
registerStanzaPlugin(OwnerAffiliations, OwnerAffiliation, iterable=True)
class OwnerConfigure(Configure): class OwnerConfigure(Configure):
name = 'configure' name = 'configure'
plugin_attrib = 'configure' plugin_attrib = 'configure'
@ -126,7 +127,6 @@ class OwnerSubscriptions(Subscriptions):
if not isinstance(subscription, OwnerSubscription): if not isinstance(subscription, OwnerSubscription):
raise TypeError raise TypeError
self.xml.append(subscription.xml) self.xml.append(subscription.xml)
return self.subscriptions.append(subscription)
registerStanzaPlugin(PubsubOwner, OwnerSubscriptions) registerStanzaPlugin(PubsubOwner, OwnerSubscriptions)
@ -142,4 +142,6 @@ class OwnerSubscription(ElementBase):
self._setAttr('jid', str(value)) self._setAttr('jid', str(value))
def getJid(self): def getJid(self):
return JID(self._getAttr('from')) return JID(self._getAttr('jid'))
registerStanzaPlugin(OwnerSubscriptions, OwnerSubscription, iterable=True)

View file

@ -693,5 +693,57 @@ class TestStreamPubsub(SleekTest):
</iq> </iq>
""") """)
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>
""")
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPubsub) suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPubsub)