From 212660091f155255ee9f45cdfca7969d8313309c Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Mon, 19 Apr 2010 01:03:27 -0700 Subject: [PATCH] added pubsub tests and fixed match on iterator error --- conn_tests/test_pubsubserver.py | 12 ++++++++++++ sleekxmpp/plugins/stanza_pubsub.py | 2 +- sleekxmpp/xmlstream/stanzabase.py | 2 ++ tests/test_pubsubstanzas.py | 12 +++++++++--- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/conn_tests/test_pubsubserver.py b/conn_tests/test_pubsubserver.py index 80b86e4..1750636 100644 --- a/conn_tests/test_pubsubserver.py +++ b/conn_tests/test_pubsubserver.py @@ -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')) diff --git a/sleekxmpp/plugins/stanza_pubsub.py b/sleekxmpp/plugins/stanza_pubsub.py index 1d8c86f..d25c2b3 100644 --- a/sleekxmpp/plugins/stanza_pubsub.py +++ b/sleekxmpp/plugins/stanza_pubsub.py @@ -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' diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 6ed5cbd..f72aa6e 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -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:]: diff --git a/tests/test_pubsubstanzas.py b/tests/test_pubsubstanzas.py index ed37314..2d1bf3b 100644 --- a/tests/test_pubsubstanzas.py +++ b/tests/test_pubsubstanzas.py @@ -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 = """This thing is awesome""" + iq['pubsub']['configure']['config'] = form + xmlstring = """This thing is awesome""" 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 = """http://jabber.org/protocol/pubsub#node_configleaf111101openpublishersnever""" + iq = self.ps.Iq(None, self.ps.ET.fromstring(xml)) + config = iq['pubsub']['configure']['config'] + self.failUnless(config.getValues() != {}) suite = unittest.TestLoader().loadTestsFromTestCase(testpubsubstanzas)