Updated pubsub stanzas to use xep_0004 stanza objects, and updated tests to match.

This commit is contained in:
Lance Stout 2010-07-20 12:18:38 -04:00
parent de24e9ed45
commit 7ad0143687
2 changed files with 503 additions and 349 deletions

View file

@ -257,7 +257,7 @@ class Configure(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
name = 'configure' name = 'configure'
plugin_attrib = name plugin_attrib = name
interfaces = set(('node', 'type', 'config')) interfaces = set(('node', 'type'))
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
@ -266,22 +266,8 @@ class Configure(ElementBase):
if not t: t == 'leaf' if not t: t == 'leaf'
return t return t
def getConfig(self):
config = self.xml.find('{jabber:x:data}x')
form = xep_0004.Form()
if config is not None:
form.fromXML(config)
return form
def setConfig(self, value):
self.xml.append(value.getXML())
return self
def delConfig(self):
config = self.xml.find('{jabber:x:data}x')
self.xml.remove(config)
registerStanzaPlugin(Pubsub, Configure) registerStanzaPlugin(Pubsub, Configure)
registerStanzaPlugin(Configure, xep_0004.Form)
class DefaultConfig(ElementBase): class DefaultConfig(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -294,27 +280,13 @@ class DefaultConfig(ElementBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
ElementBase.__init__(self, *args, **kwargs) ElementBase.__init__(self, *args, **kwargs)
def getConfig(self):
config = self.xml.find('{jabber:x:data}x')
form = xep_0004.Form()
if config is not None:
form.fromXML(config)
return form
def setConfig(self, value):
self.xml.append(value.getXML())
return self
def delConfig(self):
config = self.xml.find('{jabber:x:data}x')
self.xml.remove(config)
def getType(self): def getType(self):
t = self._getAttr('type') t = self._getAttr('type')
if not t: t = 'leaf' if not t: t = 'leaf'
return t return t
registerStanzaPlugin(PubsubOwner, DefaultConfig) registerStanzaPlugin(PubsubOwner, DefaultConfig)
registerStanzaPlugin(DefaultConfig, xep_0004.Form)
class Options(ElementBase): class Options(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -538,22 +510,8 @@ class EventConfiguration(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
def getConfig(self):
config = self.xml.find('{jabber:x:data}x')
form = xep_0004.Form()
if config is not None:
form.fromXML(config)
return form
def setConfig(self, value):
self.xml.append(value.getXML())
return self
def delConfig(self):
config = self.xml.find('{jabber:x:data}x')
self.xml.remove(config)
registerStanzaPlugin(Event, EventConfiguration) registerStanzaPlugin(Event, EventConfiguration)
registerStanzaPlugin(EventConfiguration, xep_0004.Form)
class EventPurge(ElementBase): class EventPurge(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'

View file

@ -1,315 +1,511 @@
import unittest from sleektest import *
from xml.etree import cElementTree as ET import sleekxmpp.plugins.xep_0004 as xep_0004
from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath import sleekxmpp.plugins.stanza_pubsub as pubsub
from . import xmlcompare
class testpubsubstanzas(unittest.TestCase):
def setUp(self): class TestPubsubStanzas(SleekTest):
import sleekxmpp.plugins.stanza_pubsub as ps
self.ps = ps
def testAffiliations(self): def testAffiliations(self):
"Testing iq/pubsub/affiliations/affiliation stanzas" "Testing iq/pubsub/affiliations/affiliation stanzas"
iq = self.ps.Iq() iq = self.Iq()
aff1 = self.ps.Affiliation() aff1 = pubsub.Affiliation()
aff1['node'] = 'testnode' aff1['node'] = 'testnode'
aff1['affiliation'] = 'owner' aff1['affiliation'] = 'owner'
aff2 = self.ps.Affiliation() aff2 = pubsub.Affiliation()
aff2['node'] = 'testnode2' aff2['node'] = 'testnode2'
aff2['affiliation'] = 'publisher' aff2['affiliation'] = 'publisher'
iq['pubsub']['affiliations'].append(aff1) iq['pubsub']['affiliations'].append(aff1)
iq['pubsub']['affiliations'].append(aff2) iq['pubsub']['affiliations'].append(aff2)
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><affiliations><affiliation node="testnode" affiliation="owner" /><affiliation node="testnode2" affiliation="publisher" /></affiliations></pubsub></iq>""" self.checkIq(iq, """
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <iq id="0">
iq3 = self.ps.Iq() <pubsub xmlns="http://jabber.org/protocol/pubsub">
values = iq2.getValues() <affiliations>
iq3.setValues(values) <affiliation node="testnode" affiliation="owner" />
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3), "3 methods for creating stanza don't match") <affiliation node="testnode2" affiliation="publisher" />
self.failUnless(iq.match('iq@id=0/pubsub/affiliations/affiliation@node=testnode2@affiliation=publisher'), 'Match path failed') </affiliations>
</pubsub>
</iq>""")
def testSubscriptions(self): def testSubscriptions(self):
"Testing iq/pubsub/subscriptions/subscription stanzas" "Testing iq/pubsub/subscriptions/subscription stanzas"
iq = self.ps.Iq() iq = self.Iq()
sub1 = self.ps.Subscription() sub1 = pubsub.Subscription()
sub1['node'] = 'testnode' sub1['node'] = 'testnode'
sub1['jid'] = 'steve@myserver.tld/someresource' sub1['jid'] = 'steve@myserver.tld/someresource'
sub2 = self.ps.Subscription() sub2 = pubsub.Subscription()
sub2['node'] = 'testnode2' sub2['node'] = 'testnode2'
sub2['jid'] = 'boogers@bork.top/bill' sub2['jid'] = 'boogers@bork.top/bill'
sub2['subscription'] = 'subscribed' sub2['subscription'] = 'subscribed'
iq['pubsub']['subscriptions'].append(sub1) iq['pubsub']['subscriptions'].append(sub1)
iq['pubsub']['subscriptions'].append(sub2) iq['pubsub']['subscriptions'].append(sub2)
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><subscriptions><subscription node="testnode" jid="steve@myserver.tld/someresource" /><subscription node="testnode2" jid="boogers@bork.top/bill" subscription="subscribed" /></subscriptions></pubsub></iq>""" self.checkIq(iq, """
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <iq id="0">
iq3 = self.ps.Iq() <pubsub xmlns="http://jabber.org/protocol/pubsub">
values = iq2.getValues() <subscriptions>
iq3.setValues(values) <subscription node="testnode" jid="steve@myserver.tld/someresource" />
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) <subscription node="testnode2" jid="boogers@bork.top/bill" subscription="subscribed" />
</subscriptions>
</pubsub>
</iq>""")
def testOptionalSettings(self): def testOptionalSettings(self):
"Testing iq/pubsub/subscription/subscribe-options stanzas" "Testing iq/pubsub/subscription/subscribe-options stanzas"
iq = self.ps.Iq() iq = self.Iq()
iq['pubsub']['subscription']['suboptions']['required'] = True iq['pubsub']['subscription']['suboptions']['required'] = True
iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas' iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas'
iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp" iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp"
iq['pubsub']['subscription']['subscription'] = 'unconfigured' iq['pubsub']['subscription']['subscription'] = 'unconfigured'
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/sleekxmpp" subscription="unconfigured"><subscribe-options><required /></subscribe-options></subscription></pubsub></iq>""" self.checkIq(iq, """
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <iq id="0">
iq3 = self.ps.Iq() <pubsub xmlns="http://jabber.org/protocol/pubsub">
values = iq2.getValues() <subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/sleekxmpp" subscription="unconfigured">
iq3.setValues(values) <subscribe-options>
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) <required />
</subscribe-options>
</subscription>
</pubsub>
</iq>""")
def testItems(self): def testItems(self):
"Testing iq/pubsub/items stanzas" "Testing iq/pubsub/items stanzas"
iq = self.ps.Iq() iq = self.Iq()
iq['pubsub']['items'] iq['pubsub']['items']
payload = ET.fromstring("""<thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'><child1 /><child2 normandy='cheese' foo='bar' /></thinger>""") payload = ET.fromstring("""
payload2 = ET.fromstring("""<thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'><child12 /><child22 normandy='cheese2' foo='bar2' /></thinger2>""") <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
item = self.ps.Item() <child1 />
item['id'] = 'asdf' <child2 normandy='cheese' foo='bar' />
item['payload'] = payload </thinger>""")
item2 = self.ps.Item() payload2 = ET.fromstring("""
item2['id'] = 'asdf2' <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
item2['payload'] = payload2 <child12 />
iq['pubsub']['items'].append(item) <child22 normandy='cheese2' foo='bar2' />
iq['pubsub']['items'].append(item2) </thinger2>""")
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><items><item id="asdf"><thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1"><child1 /><child2 foo="bar" normandy="cheese" /></thinger></item><item id="asdf2"><thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12"><child12 /><child22 foo="bar2" normandy="cheese2" /></thinger2></item></items></pubsub></iq>""" item = pubsub.Item()
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) item['id'] = 'asdf'
iq3 = self.ps.Iq() item['payload'] = payload
values = iq2.getValues() item2 = pubsub.Item()
iq3.setValues(values) item2['id'] = 'asdf2'
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) item2['payload'] = payload2
iq['pubsub']['items'].append(item)
iq['pubsub']['items'].append(item2)
self.checkIq(iq, """
<iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<items>
<item id="asdf">
<thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
<child1 />
<child2 foo="bar" normandy="cheese" />
</thinger>
</item>
<item id="asdf2">
<thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
<child12 />
<child22 foo="bar2" normandy="cheese2" />
</thinger2>
</item>
</items>
</pubsub>
</iq>""")
def testCreate(self): def testCreate(self):
"Testing iq/pubsub/create&configure stanzas" "Testing iq/pubsub/create&configure stanzas"
from sleekxmpp.plugins import xep_0004 iq = self.Iq()
iq = self.ps.Iq() iq['pubsub']['create']['node'] = 'mynode'
iq['pubsub']['create']['node'] = 'mynode' iq['pubsub']['configure']['form'].addField('pubsub#title',
form = xep_0004.Form() ftype='text-single',
form.addField('pubsub#title', ftype='text-single', value='This thing is awesome') value='This thing is awesome')
iq['pubsub']['configure']['config'] = form self.checkIq(iq, """
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node="mynode" /><configure><x xmlns="jabber:x:data" type="form"><field var="pubsub#title" type="text-single"><value>This thing is awesome</value></field></x></configure></pubsub></iq>""" <iq id="0">
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <pubsub xmlns="http://jabber.org/protocol/pubsub">
iq3 = self.ps.Iq() <create node="mynode" />
values = iq2.getValues() <configure>
iq3.setValues(values) <x xmlns="jabber:x:data" type="form">
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) <field var="pubsub#title" type="text-single">
<value>This thing is awesome</value>
</field>
</x>
</configure>
</pubsub>
</iq>""")
def testState(self): def testState(self):
"Testing iq/psstate stanzas" "Testing iq/psstate stanzas"
from sleekxmpp.plugins import xep_0004 iq = self.Iq()
iq = self.ps.Iq() iq['psstate']['node']= 'mynode'
iq['psstate']['node']= 'mynode' iq['psstate']['item']= 'myitem'
iq['psstate']['item']= 'myitem' pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed')
pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed') iq['psstate']['payload'] = pl
iq['psstate']['payload'] = pl self.checkIq(iq, """
xmlstring = """<iq id="0"><state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem"><claimed xmlns="http://andyet.net/protocol/pubsubqueue" /></state></iq>""" <iq id="0">
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem">
iq3 = self.ps.Iq() <claimed xmlns="http://andyet.net/protocol/pubsubqueue" />
values = iq2.getValues() </state>
iq3.setValues(values) </iq>""")
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3))
def testDefault(self): def testDefault(self):
"Testing iq/pubsub_owner/default stanzas" "Testing iq/pubsub_owner/default stanzas"
from sleekxmpp.plugins import xep_0004 iq = self.Iq()
iq = self.ps.Iq() iq['pubsub_owner']['default']
iq['pubsub_owner']['default'] iq['pubsub_owner']['default']['node'] = 'mynode'
iq['pubsub_owner']['default']['node'] = 'mynode' iq['pubsub_owner']['default']['type'] = 'leaf'
iq['pubsub_owner']['default']['type'] = 'leaf' iq['pubsub_owner']['default']['form'].addField('pubsub#title',
form = xep_0004.Form() ftype='text-single',
form.addField('pubsub#title', ftype='text-single', value='This thing is awesome') value='This thing is awesome')
iq['pubsub_owner']['default']['config'] = form self.checkIq(iq, """
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub#owner"><default node="mynode" type="leaf"><x xmlns="jabber:x:data" type="form"><field var="pubsub#title" type="text-single"><value>This thing is awesome</value></field></x></default></pubsub></iq>""" <iq id="0">
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
iq3 = self.ps.Iq() <default node="mynode" type="leaf">
values = iq2.getValues() <x xmlns="jabber:x:data" type="form">
iq3.setValues(values) <field var="pubsub#title" type="text-single">
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) <value>This thing is awesome</value>
</field>
</x>
</default>
</pubsub>
</iq>""", use_values=False)
def testSubscribe(self): def testSubscribe(self):
"Testing iq/pubsub/subscribe stanzas" "Testing iq/pubsub/subscribe stanzas"
from sleekxmpp.plugins import xep_0004 iq = self.Iq()
iq = self.ps.Iq() iq['pubsub']['subscribe']['options']
iq['pubsub']['subscribe']['options'] iq['pubsub']['subscribe']['node'] = 'cheese'
iq['pubsub']['subscribe']['node'] = 'cheese' iq['pubsub']['subscribe']['jid'] = 'fritzy@netflint.net/sleekxmpp'
iq['pubsub']['subscribe']['jid'] = 'fritzy@netflint.net/sleekxmpp' iq['pubsub']['subscribe']['options']['node'] = 'cheese'
iq['pubsub']['subscribe']['options']['node'] = 'cheese' iq['pubsub']['subscribe']['options']['jid'] = 'fritzy@netflint.net/sleekxmpp'
iq['pubsub']['subscribe']['options']['jid'] = 'fritzy@netflint.net/sleekxmpp' form = xep_0004.Form()
form = xep_0004.Form() form.addField('pubsub#title', ftype='text-single', value='This thing is awesome')
form.addField('pubsub#title', ftype='text-single', value='This thing is awesome') iq['pubsub']['subscribe']['options']['options'] = form
iq['pubsub']['subscribe']['options']['options'] = form self.checkIq(iq, """
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><subscribe node="cheese" jid="fritzy@netflint.net/sleekxmpp"><options node="cheese" jid="fritzy@netflint.net/sleekxmpp"><x xmlns="jabber:x:data" type="form"><field var="pubsub#title" type="text-single"><value>This thing is awesome</value></field></x></options></subscribe></pubsub></iq>""" <iq id="0">
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <pubsub xmlns="http://jabber.org/protocol/pubsub">
iq3 = self.ps.Iq() <subscribe node="cheese" jid="fritzy@netflint.net/sleekxmpp">
values = iq2.getValues() <options node="cheese" jid="fritzy@netflint.net/sleekxmpp">
iq3.setValues(values) <x xmlns="jabber:x:data" type="form">
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) <field var="pubsub#title" type="text-single">
<value>This thing is awesome</value>
</field>
</x>
</options>
</subscribe>
</pubsub>
</iq>""", use_values=False)
def testPublish(self): def testPublish(self):
"Testing iq/pubsub/publish stanzas" "Testing iq/pubsub/publish stanzas"
iq = self.ps.Iq() iq = self.Iq()
iq['pubsub']['publish']['node'] = 'thingers' iq['pubsub']['publish']['node'] = 'thingers'
payload = ET.fromstring("""<thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'><child1 /><child2 normandy='cheese' foo='bar' /></thinger>""") payload = ET.fromstring("""
payload2 = ET.fromstring("""<thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'><child12 /><child22 normandy='cheese2' foo='bar2' /></thinger2>""") <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
item = self.ps.Item() <child1 />
item['id'] = 'asdf' <child2 normandy='cheese' foo='bar' />
item['payload'] = payload </thinger>""")
item2 = self.ps.Item() payload2 = ET.fromstring("""
item2['id'] = 'asdf2' <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
item2['payload'] = payload2 <child12 />
iq['pubsub']['publish'].append(item) <child22 normandy='cheese2' foo='bar2' />
iq['pubsub']['publish'].append(item2) </thinger2>""")
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><publish node="thingers"><item id="asdf"><thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1"><child1 /><child2 foo="bar" normandy="cheese" /></thinger></item><item id="asdf2"><thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12"><child12 /><child22 foo="bar2" normandy="cheese2" /></thinger2></item></publish></pubsub></iq>""" item = pubsub.Item()
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) item['id'] = 'asdf'
iq3 = self.ps.Iq() item['payload'] = payload
values = iq2.getValues() item2 = pubsub.Item()
iq3.setValues(values) item2['id'] = 'asdf2'
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) item2['payload'] = payload2
iq['pubsub']['publish'].append(item)
iq['pubsub']['publish'].append(item2)
def testDelete(self): self.checkIq(iq, """
"Testing iq/pubsub_owner/delete stanzas" <iq id="0">
iq = self.ps.Iq() <pubsub xmlns="http://jabber.org/protocol/pubsub">
iq['pubsub_owner']['delete']['node'] = 'thingers' <publish node="thingers">
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub#owner"><delete node="thingers" /></pubsub></iq>""" <item id="asdf">
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) <thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
iq3 = self.ps.Iq() <child1 />
iq3.setValues(iq2.getValues()) <child2 foo="bar" normandy="cheese" />
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) </thinger>
</item>
<item id="asdf2">
<thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
<child12 />
<child22 foo="bar2" normandy="cheese2" />
</thinger2>
</item>
</publish>
</pubsub>
</iq>""")
def testCreateConfigGet(self): def testDelete(self):
"""Testing getting config from full create""" "Testing iq/pubsub_owner/delete stanzas"
xml = """<iq to="pubsub.asdf" type="set" id="E" from="fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node="testnode2" /><configure><x xmlns="jabber:x:data" type="submit"><field var="FORM_TYPE" type="hidden"><value>http://jabber.org/protocol/pubsub#node_config</value></field><field var="pubsub#node_type" type="list-single" label="Select the node type"><value>leaf</value></field><field var="pubsub#title" type="text-single" label="A friendly name for the node" /><field var="pubsub#deliver_notifications" type="boolean" label="Deliver event notifications"><value>1</value></field><field var="pubsub#deliver_payloads" type="boolean" label="Deliver payloads with event notifications"><value>1</value></field><field var="pubsub#notify_config" type="boolean" label="Notify subscribers when the node configuration changes" /><field var="pubsub#notify_delete" type="boolean" label="Notify subscribers when the node is deleted" /><field var="pubsub#notify_retract" type="boolean" label="Notify subscribers when items are removed from the node"><value>1</value></field><field var="pubsub#notify_sub" type="boolean" label="Notify owners about new subscribers and unsubscribes" /><field var="pubsub#persist_items" type="boolean" label="Persist items in storage" /><field var="pubsub#max_items" type="text-single" label="Max # of items to persist"><value>10</value></field><field var="pubsub#subscribe" type="boolean" label="Whether to allow subscriptions"><value>1</value></field><field var="pubsub#access_model" type="list-single" label="Specify the subscriber model"><value>open</value></field><field var="pubsub#publish_model" type="list-single" label="Specify the publisher model"><value>publishers</value></field><field var="pubsub#send_last_published_item" type="list-single" label="Send last published item"><value>never</value></field><field var="pubsub#presence_based_delivery" type="boolean" label="Deliver notification only to available users" /></x></configure></pubsub></iq>""" iq = self.Iq()
iq = self.ps.Iq(None, self.ps.ET.fromstring(xml)) iq['pubsub_owner']['delete']['node'] = 'thingers'
config = iq['pubsub']['configure']['config'] self.checkIq(iq, """
self.failUnless(config.getValues() != {}) <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
<delete node="thingers" />
</pubsub>
</iq>""")
def testItemEvent(self): def testCreateConfigGet(self):
"""Testing message/pubsub_event/items/item""" """Testing getting config from full create"""
msg = self.ps.Message() iq = self.Iq()
item = self.ps.EventItem() iq['to'] = 'pubsub.asdf'
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) iq['from'] = 'fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7'
item['payload'] = pl iq['type'] = 'set'
item['id'] = 'abc123' iq['id'] = 'E'
msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal'
xmlstring = """<message type="normal"><event xmlns="http://jabber.org/protocol/pubsub#event"><items node="cheese"><item id="abc123"><test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" /></item></items></event></message>"""
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring))
msg3 = self.ps.Message()
msg3.setValues(msg2.getValues())
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3))
def testItemsEvent(self): pub = iq['pubsub']
"""Testing multiple message/pubsub_event/items/item""" pub['create']['node'] = 'testnode2'
msg = self.ps.Message() pub['configure']['form']['type'] = 'submit'
item = self.ps.EventItem() pub['configure']['form'].setFields([
item2 = self.ps.EventItem() ('FORM_TYPE', {'type': 'hidden',
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) 'value': 'http://jabber.org/protocol/pubsub#node_config'}),
pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'}) ('pubsub#node_type', {'type': 'list-single',
item2['payload'] = pl2 'label': 'Select the node type',
item['payload'] = pl 'value': 'leaf'}),
item['id'] = 'abc123' ('pubsub#title', {'type': 'text-single',
item2['id'] = '123abc' 'label': 'A friendly name for the node'}),
msg['pubsub_event']['items'].append(item) ('pubsub#deliver_notifications', {'type': 'boolean',
msg['pubsub_event']['items'].append(item2) 'label': 'Deliver event notifications',
msg['pubsub_event']['items']['node'] = 'cheese' 'value': True}),
msg['type'] = 'normal' ('pubsub#deliver_payloads', {'type': 'boolean',
xmlstring = """<message type="normal"><event xmlns="http://jabber.org/protocol/pubsub#event"><items node="cheese"><item id="abc123"><test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" /></item><item id="123abc"><test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" /></item></items></event></message>""" 'label': 'Deliver payloads with event notifications',
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) 'value': True}),
msg3 = self.ps.Message() ('pubsub#notify_config', {'type': 'boolean',
msg3.setValues(msg2.getValues()) 'label': 'Notify subscribers when the node configuration changes'}),
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3)) ('pubsub#notify_delete', {'type': 'boolean',
'label': 'Notify subscribers when the node is deleted'}),
('pubsub#notify_retract', {'type': 'boolean',
'label': 'Notify subscribers when items are removed from the node',
'value': True}),
('pubsub#notify_sub', {'type': 'boolean',
'label': 'Notify owners about new subscribers and unsubscribes'}),
('pubsub#persist_items', {'type': 'boolean',
'label': 'Persist items in storage'}),
('pubsub#max_items', {'type': 'text-single',
'label': 'Max # of items to persist',
'value': '10'}),
('pubsub#subscribe', {'type': 'boolean',
'label': 'Whether to allow subscriptions',
'value': True}),
('pubsub#access_model', {'type': 'list-single',
'label': 'Specify the subscriber model',
'value': 'open'}),
('pubsub#publish_model', {'type': 'list-single',
'label': 'Specify the publisher model',
'value': 'publishers'}),
('pubsub#send_last_published_item', {'type': 'list-single',
'label': 'Send last published item',
'value': 'never'}),
('pubsub#presence_based_delivery', {'type': 'boolean',
'label': 'Deliver notification only to available users'}),
])
def testItemsEvent(self): self.checkIq(iq, """
"""Testing message/pubsub_event/items/item & retract mix""" <iq to="pubsub.asdf" type="set" id="E" from="fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7">
msg = self.ps.Message() <pubsub xmlns="http://jabber.org/protocol/pubsub">
item = self.ps.EventItem() <create node="testnode2" />
item2 = self.ps.EventItem() <configure>
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) <x xmlns="jabber:x:data" type="submit">
pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'}) <field var="FORM_TYPE" type="hidden">
item2['payload'] = pl2 <value>http://jabber.org/protocol/pubsub#node_config</value>
retract = self.ps.EventRetract() </field>
retract['id'] = 'aabbcc' <field var="pubsub#node_type" type="list-single" label="Select the node type">
item['payload'] = pl <value>leaf</value>
item['id'] = 'abc123' </field>
item2['id'] = '123abc' <field var="pubsub#title" type="text-single" label="A friendly name for the node" />
msg['pubsub_event']['items'].append(item) <field var="pubsub#deliver_notifications" type="boolean" label="Deliver event notifications">
msg['pubsub_event']['items'].append(retract) <value>1</value>
msg['pubsub_event']['items'].append(item2) </field>
msg['pubsub_event']['items']['node'] = 'cheese' <field var="pubsub#deliver_payloads" type="boolean" label="Deliver payloads with event notifications">
msg['type'] = 'normal' <value>1</value>
xmlstring = """<message type="normal"><event xmlns="http://jabber.org/protocol/pubsub#event"><items node="cheese"><item id="abc123"><test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" /></item><retract id="aabbcc" /><item id="123abc"><test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" /></item></items></event></message>""" </field>
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) <field var="pubsub#notify_config" type="boolean" label="Notify subscribers when the node configuration changes" />
msg3 = self.ps.Message() <field var="pubsub#notify_delete" type="boolean" label="Notify subscribers when the node is deleted" />
msg3.setValues(msg2.getValues()) <field var="pubsub#notify_retract" type="boolean" label="Notify subscribers when items are removed from the node">
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3)) <value>1</value>
</field>
<field var="pubsub#notify_sub" type="boolean" label="Notify owners about new subscribers and unsubscribes" />
<field var="pubsub#persist_items" type="boolean" label="Persist items in storage" />
<field var="pubsub#max_items" type="text-single" label="Max # of items to persist">
<value>10</value>
</field>
<field var="pubsub#subscribe" type="boolean" label="Whether to allow subscriptions">
<value>1</value>
</field>
<field var="pubsub#access_model" type="list-single" label="Specify the subscriber model">
<value>open</value>
</field>
<field var="pubsub#publish_model" type="list-single" label="Specify the publisher model">
<value>publishers</value>
</field>
<field var="pubsub#send_last_published_item" type="list-single" label="Send last published item">
<value>never</value>
</field>
<field var="pubsub#presence_based_delivery" type="boolean" label="Deliver notification only to available users" />
</x>
</configure>
</pubsub>
</iq>""")
def testCollectionAssociate(self): def testItemEvent(self):
"""Testing message/pubsub_event/collection/associate""" """Testing message/pubsub_event/items/item"""
msg = self.ps.Message() msg = self.Message()
msg['pubsub_event']['collection']['associate']['node'] = 'cheese' item = pubsub.EventItem()
msg['pubsub_event']['collection']['node'] = 'cheeseburger' pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
msg['type'] = 'headline' item['payload'] = pl
xmlstring = """<message type="headline"><event xmlns="http://jabber.org/protocol/pubsub#event"><collection node="cheeseburger"><associate node="cheese" /></collection></event></message>""" item['id'] = 'abc123'
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) msg['pubsub_event']['items'].append(item)
msg3 = self.ps.Message() msg['pubsub_event']['items']['node'] = 'cheese'
msg3.setValues(msg2.getValues()) msg['type'] = 'normal'
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3)) self.checkMessage(msg, """
<message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese">
<item id="abc123">
<test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
</item>
</items>
</event>
</message>""")
def testCollectionDisassociate(self): def testItemsEvent(self):
"""Testing message/pubsub_event/collection/disassociate""" """Testing multiple message/pubsub_event/items/item"""
msg = self.ps.Message() msg = self.Message()
msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese' item = pubsub.EventItem()
msg['pubsub_event']['collection']['node'] = 'cheeseburger' item2 = pubsub.EventItem()
msg['type'] = 'headline' pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
xmlstring = """<message type="headline"><event xmlns="http://jabber.org/protocol/pubsub#event"><collection node="cheeseburger"><disassociate node="cheese" /></collection></event></message>""" pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) item2['payload'] = pl2
msg3 = self.ps.Message() item['payload'] = pl
msg3.setValues(msg2.getValues()) item['id'] = 'abc123'
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3)) item2['id'] = '123abc'
msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items'].append(item2)
msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal'
self.checkMessage(msg, """
<message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese">
<item id="abc123">
<test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
</item>
<item id="123abc">
<test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
</item>
</items>
</event>
</message>""")
def testEventConfiguration(self): def testItemsEvent(self):
"""Testing message/pubsub_event/configuration/config""" """Testing message/pubsub_event/items/item & retract mix"""
msg = self.ps.Message() msg = self.Message()
from sleekxmpp.plugins import xep_0004 item = pubsub.EventItem()
form = xep_0004.Form() item2 = pubsub.EventItem()
form.addField('pubsub#title', ftype='text-single', value='This thing is awesome') pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
msg['pubsub_event']['configuration']['node'] = 'cheese' pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
msg['pubsub_event']['configuration']['config'] = form item2['payload'] = pl2
msg['type'] = 'headline' retract = pubsub.EventRetract()
xmlstring = """<message type="headline"><event xmlns="http://jabber.org/protocol/pubsub#event"><configuration node="cheese"><x xmlns="jabber:x:data" type="form"><field var="pubsub#title" type="text-single"><value>This thing is awesome</value></field></x></configuration></event></message>""" retract['id'] = 'aabbcc'
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) item['payload'] = pl
msg3 = self.ps.Message() item['id'] = 'abc123'
msg3.setValues(msg2.getValues()) item2['id'] = '123abc'
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3)) msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items'].append(retract)
msg['pubsub_event']['items'].append(item2)
msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal'
self.checkMessage(msg, """
<message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese">
<item id="abc123">
<test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
</item><retract id="aabbcc" />
<item id="123abc">
<test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
</item>
</items>
</event>
</message>""")
def testEventPurge(self): def testCollectionAssociate(self):
"""Testing message/pubsub_event/purge""" """Testing message/pubsub_event/collection/associate"""
msg = self.ps.Message() msg = self.Message()
msg['pubsub_event']['purge']['node'] = 'pickles' msg['pubsub_event']['collection']['associate']['node'] = 'cheese'
msg['type'] = 'headline' msg['pubsub_event']['collection']['node'] = 'cheeseburger'
xmlstring = """<message type="headline"><event xmlns="http://jabber.org/protocol/pubsub#event"><purge node="pickles" /></event></message>""" msg['type'] = 'headline'
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) self.checkMessage(msg, """
msg3 = self.ps.Message() <message type="headline">
msg3.setValues(msg2.getValues()) <event xmlns="http://jabber.org/protocol/pubsub#event">
self.failUnless(xmlstring == str(msg) == str(msg2) == str(msg3)) <collection node="cheeseburger">
<associate node="cheese" />
</collection>
</event>
</message>""")
def testEventSubscription(self): def testCollectionDisassociate(self):
"""Testing message/pubsub_event/subscription""" """Testing message/pubsub_event/collection/disassociate"""
msg = self.ps.Message() msg = self.Message()
msg['pubsub_event']['subscription']['node'] = 'pickles' msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese'
msg['pubsub_event']['subscription']['jid'] = 'fritzy@netflint.net/test' msg['pubsub_event']['collection']['node'] = 'cheeseburger'
msg['pubsub_event']['subscription']['subid'] = 'aabb1122' msg['type'] = 'headline'
msg['pubsub_event']['subscription']['subscription'] = 'subscribed' self.checkMessage(msg, """
msg['pubsub_event']['subscription']['expiry'] = 'presence' <message type="headline">
msg['type'] = 'headline' <event xmlns="http://jabber.org/protocol/pubsub#event">
xmlstring = """<message type="headline"><event xmlns="http://jabber.org/protocol/pubsub#event"><subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" /></event></message>""" <collection node="cheeseburger">
msg2 = self.ps.Message(None, self.ps.ET.fromstring(xmlstring)) <disassociate node="cheese" />
msg3 = self.ps.Message() </collection>
msg3.setValues(msg2.getValues()) </event>
self.failUnless(xmlcompare.comparemany([xmlstring, str(msg), str(msg2), str(msg3)])) </message>""")
suite = unittest.TestLoader().loadTestsFromTestCase(testpubsubstanzas) def testEventConfiguration(self):
"""Testing message/pubsub_event/configuration/config"""
msg = self.Message()
msg['pubsub_event']['configuration']['node'] = 'cheese'
msg['pubsub_event']['configuration']['form'].addField('pubsub#title',
ftype='text-single',
value='This thing is awesome')
msg['type'] = 'headline'
self.checkMessage(msg, """
<message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<configuration node="cheese">
<x xmlns="jabber:x:data" type="form">
<field var="pubsub#title" type="text-single">
<value>This thing is awesome</value>
</field>
</x>
</configuration>
</event>
</message>""")
def testEventPurge(self):
"""Testing message/pubsub_event/purge"""
msg = self.Message()
msg['pubsub_event']['purge']['node'] = 'pickles'
msg['type'] = 'headline'
self.checkMessage(msg, """
<message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<purge node="pickles" />
</event>
</message>""")
def testEventSubscription(self):
"""Testing message/pubsub_event/subscription"""
msg = self.Message()
msg['pubsub_event']['subscription']['node'] = 'pickles'
msg['pubsub_event']['subscription']['jid'] = 'fritzy@netflint.net/test'
msg['pubsub_event']['subscription']['subid'] = 'aabb1122'
msg['pubsub_event']['subscription']['subscription'] = 'subscribed'
msg['pubsub_event']['subscription']['expiry'] = 'presence'
msg['type'] = 'headline'
self.checkMessage(msg, """
<message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" />
</event>
</message>""")
suite = unittest.TestLoader().loadTestsFromTestCase(TestPubsubStanzas)