Users can retrieve their affiliations now, with tests.

This commit is contained in:
Lance Stout 2011-09-01 11:30:55 -07:00
parent ec01e45ed1
commit afbd506cfc
3 changed files with 34 additions and 1 deletions

View file

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

View file

@ -37,7 +37,7 @@ class Affiliations(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
name = 'affiliations' name = 'affiliations'
plugin_attrib = 'affiliations' plugin_attrib = 'affiliations'
interfaces = set(tuple()) interfaces = set(('node',))
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
subitem = (Affiliation,) subitem = (Affiliation,)

View file

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