added pubsub tests and fixed match on iterator error

This commit is contained in:
Nathan Fritz 2010-04-19 01:03:27 -07:00
parent 35c157f9d8
commit 212660091f
4 changed files with 24 additions and 4 deletions

View file

@ -66,8 +66,20 @@ class TestPubsubServer(unittest.TestCase):
#print("%s == %s" % (nconfig.getValues(), self.statev['defaultconfig'].getValues()))
self.failUnless(nconfig.getValues() == self.statev['defaultconfig'].getValues(), "Configuration does not match")
self.failUnless(self.xmpp1['xep_0060'].setNodeConfig(self.pshost, 'testnode2', nconfig))
def test006subscribetonode(self):
"""Subscribe to node from account 2"""
self.failUnless(self.xmpp2['xep_0060'].subscribe(self.pshost, "testnode2"))
def test007publishitem(self):
"""Publishing item"""
item = ET.Element('{http://netflint.net/protocol/test}test')
result = self.xmpp1['xep_0060'].setItem(self.pshost, "testnode2", (('test_node1', item),))
self.failUnless(result)
#need to add check for update
def test999cleanup(self):
"Cleaning up"
self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode2'))

View file

@ -2,6 +2,7 @@ from .. xmlstream.stanzabase import ElementBase, ET, JID
from .. stanza.iq import Iq
from .. basexmpp import basexmpp
from .. xmlstream.xmlstream import XMLStream
import logging
from . import xep_0004
def stanzaPlugin(stanza, plugin):
@ -283,7 +284,6 @@ class Configure(ElementBase):
self.xml.remove(config)
stanzaPlugin(Pubsub, Configure)
stanzaPlugin(Create, Configure)
class DefaultConfig(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner'

View file

@ -120,6 +120,8 @@ class ElementBase(tostring.ToString):
if tagargs[0] not in (self.plugins, self.plugin_attrib): return False
founditerable = False
for iterable in self.iterables:
if nodes[1:] == []:
break
founditerable = iterable.match(nodes[1:])
if founditerable: break;
for evals in tagargs[1:]:

View file

@ -85,12 +85,11 @@ class testpubsubstanzas(unittest.TestCase):
"Testing iq/pubsub/create&configure stanzas"
from sleekxmpp.plugins import xep_0004
iq = self.ps.Iq()
iq['pubsub']['create']['configure']
iq['pubsub']['create']['node'] = 'mynode'
form = xep_0004.Form()
form.addField('pubsub#title', ftype='text-single', value='This thing is awesome')
iq['pubsub']['create']['configure']['config'] = form
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></create></pubsub></iq>"""
iq['pubsub']['configure']['config'] = form
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>"""
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring))
iq3 = self.ps.Iq()
values = iq2.getValues()
@ -162,5 +161,12 @@ class testpubsubstanzas(unittest.TestCase):
iq3 = self.ps.Iq()
iq3.setValues(iq2.getValues())
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3))
def testCreateConfigGet(self):
"""Testing getting config from full create"""
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.ps.Iq(None, self.ps.ET.fromstring(xml))
config = iq['pubsub']['configure']['config']
self.failUnless(config.getValues() != {})
suite = unittest.TestLoader().loadTestsFromTestCase(testpubsubstanzas)