mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-23 19:19:53 +00:00
bugfixes and continuing to work on pubsub tests
This commit is contained in:
parent
37b571c55a
commit
602a6d8491
4 changed files with 51 additions and 38 deletions
|
@ -8,6 +8,8 @@ import sys
|
|||
import thread
|
||||
import unittest
|
||||
import sleekxmpp.plugins.xep_0004
|
||||
from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath
|
||||
from sleekxmpp.xmlstream.handler.waiter import Waiter
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
|
@ -74,13 +76,47 @@ class TestPubsubServer(unittest.TestCase):
|
|||
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),))
|
||||
w = Waiter('wait publish', StanzaPath('message/pubsub_event/items'))
|
||||
self.xmpp2.registerHandler(w)
|
||||
result = self.xmpp1['xep_0060'].setItem(self.pshost, "testnode2", (('test1', item),))
|
||||
msg = w.wait(5) # got to get a result in 5 seconds
|
||||
self.failUnless(msg != False, "Account #2 did not get message event")
|
||||
self.failUnless(result)
|
||||
#need to add check for update
|
||||
|
||||
def test008updateitem(self):
|
||||
"""Updating item"""
|
||||
item = ET.Element('{http://netflint.net/protocol/test}test', {'someattr': 'hi there'})
|
||||
w = Waiter('wait publish', StanzaPath('message/pubsub_event/items'))
|
||||
self.xmpp2.registerHandler(w)
|
||||
result = self.xmpp1['xep_0060'].setItem(self.pshost, "testnode2", (('test1', item),))
|
||||
msg = w.wait(5) # got to get a result in 5 seconds
|
||||
self.failUnless(msg != False, "Account #2 did not get message event")
|
||||
self.failUnless(result)
|
||||
#need to add check for update
|
||||
|
||||
def test009deleteitem(self):
|
||||
"""Deleting item"""
|
||||
w = Waiter('wait retract', StanzaPath('message/pubsub_event/items@node=testnode2'))
|
||||
self.xmpp2.registerHandler(w)
|
||||
result = self.xmpp1['xep_0060'].deleteItem(self.pshost, "testnode2", "test1")
|
||||
self.failUnless(result, "Got error when deleting item.")
|
||||
msg = w.wait(1)
|
||||
self.failUnless(msg != False, "Did not get retract notice.")
|
||||
|
||||
def test010unsubscribenode(self):
|
||||
"Unsubscribing Account #2"
|
||||
self.failUnless(self.xmpp2['xep_0060'].unsubscribe(self.pshost, "testnode2"), "Got error response when unsubscribing.")
|
||||
|
||||
def test011createcollectionnode(self):
|
||||
"Create a collection node"
|
||||
self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, "testnode3", self.statev['defaultconfig'], True))
|
||||
|
||||
|
||||
def test999cleanup(self):
|
||||
"Cleaning up"
|
||||
self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode2'))
|
||||
self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode5'), "Could not delete test node.")
|
||||
self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode3'), "Could not delete collection test node.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -81,39 +81,6 @@ class Subscriptions(ElementBase):
|
|||
plugin_tag_map = {}
|
||||
subitem = (Subscription,)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
ElementBase.__init__(self, *args, **kwargs)
|
||||
self.subscriptions = []
|
||||
self.idx = 0
|
||||
|
||||
def __iter__(self):
|
||||
self.idx = 0
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
self.idx += 1
|
||||
if self.idx + 1 > len(self.subscriptions):
|
||||
self.idx = 0
|
||||
raise StopIteration
|
||||
return self.subscriptions[self.idx]
|
||||
|
||||
def __len__(self):
|
||||
return len(self.subscriptions)
|
||||
|
||||
def append(self, subscription):
|
||||
if not isinstance(subscription, Subscription):
|
||||
raise TypeError
|
||||
self.xml.append(subscription.xml)
|
||||
return self.subscriptions.append(subscription)
|
||||
|
||||
def pop(self, idx=0):
|
||||
aff = self.subscriptions.pop(idx)
|
||||
self.xml.remove(aff.xml)
|
||||
return aff
|
||||
|
||||
def find(self, subscription):
|
||||
return self.subscriptions.find(subscription)
|
||||
|
||||
stanzaPlugin(Pubsub, Subscriptions)
|
||||
|
||||
class OptionalSetting(object):
|
||||
|
|
|
@ -10,6 +10,7 @@ from xml.etree import cElementTree as ET
|
|||
from . error import Error
|
||||
from .. exceptions import XMPPError
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
class RootStanza(StanzaBase):
|
||||
|
||||
|
@ -24,7 +25,10 @@ class RootStanza(StanzaBase):
|
|||
self['error']['type'] = e.etype
|
||||
else: # we probably didn't raise this on purpose, so send back a traceback
|
||||
self['error']['condition'] = 'undefined-condition'
|
||||
self['error']['text'] = traceback.format_tb(e.__traceback__)
|
||||
if sys.version_info < (3,0):
|
||||
self['error']['text'] = "SleekXMPP got into trouble."
|
||||
else:
|
||||
self['error']['text'] = traceback.format_tb(e.__traceback__)
|
||||
self.send()
|
||||
|
||||
# all jabber:client root stanzas should have the error plugin
|
||||
|
|
|
@ -77,11 +77,14 @@ class ElementBase(tostring.ToString):
|
|||
|
||||
def __next__(self):
|
||||
self.idx += 1
|
||||
if self.idx + 1 > len(self.iterables):
|
||||
if self.idx > len(self.iterables):
|
||||
self.idx = 0
|
||||
raise StopIteration
|
||||
return self.affiliations[self.idx]
|
||||
return self.iterables[self.idx - 1]
|
||||
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
||||
def __len__(self):
|
||||
return len(self.iterables)
|
||||
|
||||
|
@ -140,6 +143,9 @@ class ElementBase(tostring.ToString):
|
|||
|
||||
def find(self, xpath): # for backwards compatiblity, expose elementtree interface
|
||||
return self.xml.find(xpath)
|
||||
|
||||
def findall(self, xpath):
|
||||
return self.xml.findall(xpath)
|
||||
|
||||
def setup(self, xml=None):
|
||||
if self.xml is None:
|
||||
|
|
Loading…
Reference in a new issue