adding tests, fixed stanzapath matching to match keys, fixed pubsub#owner stanzas

This commit is contained in:
Nathan Fritz 2010-04-14 01:23:17 -07:00
parent 2f9f649d98
commit 80e7e0d0ee
6 changed files with 22 additions and 46 deletions

View file

@ -286,39 +286,6 @@ stanzaPlugin(Pubsub, Configure)
stanzaPlugin(Create, Configure) stanzaPlugin(Create, Configure)
class DefaultConfig(ElementBase): class DefaultConfig(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'default'
plugin_attrib = 'default'
interfaces = set(('node', 'type', 'config'))
plugin_attrib_map = {}
plugin_tag_map = {}
def __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):
t = self._getAttr('type')
if not t: t == 'leaf'
return t
stanzaPlugin(Pubsub, DefaultConfig)
class DefaultConfigOwner(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
name = 'default' name = 'default'
plugin_attrib = 'default' plugin_attrib = 'default'
@ -440,6 +407,7 @@ class OwnerDelete(ElementBase, OptionalSetting):
plugin_attrib = 'delete' plugin_attrib = 'delete'
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
interfaces = set(('node',))
stanzaPlugin(PubsubOwner, OwnerDelete) stanzaPlugin(PubsubOwner, OwnerDelete)

View file

@ -16,6 +16,7 @@ class Iq(RootStanza):
interfaces = set(('type', 'to', 'from', 'id','query')) interfaces = set(('type', 'to', 'from', 'id','query'))
types = set(('get', 'result', 'set', 'error')) types = set(('get', 'result', 'set', 'error'))
name = 'iq' name = 'iq'
plugin_attrib = name
namespace = 'jabber:client' namespace = 'jabber:client'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View file

@ -15,6 +15,7 @@ class Message(RootStanza):
types = set((None, 'normal', 'chat', 'headline', 'error', 'groupchat')) types = set((None, 'normal', 'chat', 'headline', 'error', 'groupchat'))
sub_interfaces = set(('body', 'subject')) sub_interfaces = set(('body', 'subject'))
name = 'message' name = 'message'
plugin_attrib = name
namespace = 'jabber:client' namespace = 'jabber:client'
def getType(self): def getType(self):

View file

@ -16,6 +16,7 @@ class Presence(RootStanza):
showtypes = set(('dnd', 'chat', 'xa', 'away')) showtypes = set(('dnd', 'chat', 'xa', 'away'))
sub_interfaces = set(('status', 'priority')) sub_interfaces = set(('status', 'priority'))
name = 'presence' name = 'presence'
plugin_attrib = name
namespace = 'jabber:client' namespace = 'jabber:client'
def getShowElement(self): def getShowElement(self):

View file

@ -117,7 +117,7 @@ class ElementBase(tostring.ToString):
else: else:
nodes = matchstring nodes = matchstring
tagargs = nodes[0].split('@') tagargs = nodes[0].split('@')
if tagargs[0] not in (self.plugins, self.name): return False if tagargs[0] not in (self.plugins, self.plugin_attrib): return False
founditerable = False founditerable = False
for iterable in self.iterables: for iterable in self.iterables:
founditerable = iterable.match(nodes[1:]) founditerable = iterable.match(nodes[1:])
@ -325,8 +325,8 @@ class StanzaBase(ElementBase):
def clear(self): def clear(self):
for child in self.xml.getchildren(): for child in self.xml.getchildren():
self.xml.remove(child) self.xml.remove(child)
#for plugin in list(self.plugins.keys()): for plugin in list(self.plugins.keys()):
# del self.plugins[plugin] del self.plugins[plugin]
def reply(self): def reply(self):
self['from'], self['to'] = self['to'], self['from'] self['from'], self['to'] = self['to'], self['from']

View file

@ -98,15 +98,15 @@ class testpubsubstanzas(unittest.TestCase):
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3))
def testDefault(self): def testDefault(self):
"Testing iq/default stanzas" "Testing iq/pubsub_owner/default stanzas"
from sleekxmpp.plugins import xep_0004 from sleekxmpp.plugins import xep_0004
iq = self.ps.Iq() iq = self.ps.Iq()
iq['pubsub']['default'] iq['pubsub_owner']['default']
iq['pubsub']['default']['node'] = 'mynode' iq['pubsub_owner']['default']['node'] = 'mynode'
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']['default']['config'] = form iq['pubsub_owner']['default']['config'] = form
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub"><default node="mynode"><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>""" xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub#owner"><default node="mynode"><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>"""
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring)) iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring))
iq3 = self.ps.Iq() iq3 = self.ps.Iq()
values = iq2.getValues() values = iq2.getValues()
@ -151,11 +151,16 @@ class testpubsubstanzas(unittest.TestCase):
iq3 = self.ps.Iq() iq3 = self.ps.Iq()
values = iq2.getValues() values = iq2.getValues()
iq3.setValues(values) iq3.setValues(values)
#print() self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3))
#print(xmlstring)
#print(iq) def testDelete(self):
#print(iq2) "Testing iq/pubsub_owner/delete stanzas"
#print(iq3) iq = self.ps.Iq()
iq['pubsub_owner']['delete']['node'] = 'thingers'
xmlstring = """<iq id="0"><pubsub xmlns="http://jabber.org/protocol/pubsub#owner"><delete node="thingers" /></pubsub></iq>"""
iq2 = self.ps.Iq(None, self.ps.ET.fromstring(xmlstring))
iq3 = self.ps.Iq()
iq3.setValues(iq2.getValues())
self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3)) self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3))
suite = unittest.TestLoader().loadTestsFromTestCase(testpubsubstanzas) suite = unittest.TestLoader().loadTestsFromTestCase(testpubsubstanzas)