diff options
author | Lance Stout <lancestout@gmail.com> | 2012-05-16 11:57:55 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-05-16 11:57:55 -0700 |
commit | 74d1f88146be94321e69cc2e18b070767946e42f (patch) | |
tree | fd79b5e81380d6f53c513660bb0bc1f26b45da77 | |
parent | 7842c55da3fa13b910a626f75bdde949dafb1b89 (diff) | |
download | slixmpp-74d1f88146be94321e69cc2e18b070767946e42f.tar.gz slixmpp-74d1f88146be94321e69cc2e18b070767946e42f.tar.bz2 slixmpp-74d1f88146be94321e69cc2e18b070767946e42f.tar.xz slixmpp-74d1f88146be94321e69cc2e18b070767946e42f.zip |
Prune unused conn_test code.
-rw-r--r-- | conn_tests/test_pubsubjobs.py | 171 | ||||
-rw-r--r-- | conn_tests/test_pubsubserver.py | 233 | ||||
-rw-r--r-- | conn_tests/testconfig.ini | 13 | ||||
-rwxr-xr-x | conn_tests/testpubsub.py | 350 |
4 files changed, 0 insertions, 767 deletions
diff --git a/conn_tests/test_pubsubjobs.py b/conn_tests/test_pubsubjobs.py deleted file mode 100644 index ec2a2716..00000000 --- a/conn_tests/test_pubsubjobs.py +++ /dev/null @@ -1,171 +0,0 @@ -import logging -import sleekxmpp -from optparse import OptionParser -from xml.etree import cElementTree as ET -import os -import time -import sys -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: - import ConfigParser as configparser -try: - import queue -except ImportError: - import Queue as queue - -class TestClient(sleekxmpp.ClientXMPP): - def __init__(self, jid, password): - sleekxmpp.ClientXMPP.__init__(self, jid, password) - self.add_event_handler("session_start", self.start) - #self.add_event_handler("message", self.message) - self.waitforstart = queue.Queue() - - def start(self, event): - self.getRoster() - self.sendPresence() - self.waitforstart.put(True) - - -class TestPubsubServer(unittest.TestCase): - statev = {} - - def __init__(self, *args, **kwargs): - unittest.TestCase.__init__(self, *args, **kwargs) - - def setUp(self): - pass - - def test001getdefaultconfig(self): - """Get the default node config""" - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode2') - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode3') - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode4') - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode5') - result = self.xmpp1['xep_0060'].getNodeConfig(self.pshost) - self.statev['defaultconfig'] = result - self.failUnless(isinstance(result, sleekxmpp.plugins.xep_0004.Form)) - - def test002createdefaultnode(self): - """Create a node without config""" - self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, 'testnode1')) - - def test003deletenode(self): - """Delete recently created node""" - self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode1')) - - def test004createnode(self): - """Create a node with a config""" - self.statev['defaultconfig'].field['pubsub#access_model'].setValue('open') - self.statev['defaultconfig'].field['pubsub#notify_retract'].setValue(True) - self.statev['defaultconfig'].field['pubsub#persist_items'].setValue(True) - self.statev['defaultconfig'].field['pubsub#presence_based_delivery'].setValue(True) - p = self.xmpp2.Presence() - p['to'] = self.pshost - p.send() - self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, 'testnode2', self.statev['defaultconfig'], ntype='job')) - - def test005reconfigure(self): - """Retrieving node config and reconfiguring""" - nconfig = self.xmpp1['xep_0060'].getNodeConfig(self.pshost, 'testnode2') - self.failUnless(nconfig, "No configuration returned") - #print("\n%s ==\n %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') - w = Waiter('wait publish', StanzaPath('message/pubsub_event/items')) - self.xmpp2.registerHandler(w) - #result = self.xmpp1['xep_0060'].setItem(self.pshost, "testnode2", (('test1', item),)) - result = self.xmpp1['jobs'].createJob(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") - #result = self.xmpp1['xep_0060'].setItem(self.pshost, "testnode2", (('test2', item),)) - result = self.xmpp1['jobs'].createJob(self.pshost, "testnode2", 'test2', item) - w = Waiter('wait publish2', StanzaPath('message/pubsub_event/items')) - self.xmpp2.registerHandler(w) - self.xmpp2['jobs'].claimJob(self.pshost, 'testnode2', 'test1') - msg = w.wait(5) # got to get a result in 5 seconds - self.xmpp2['jobs'].claimJob(self.pshost, 'testnode2', 'test2') - self.xmpp2['jobs'].finishJob(self.pshost, 'testnode2', 'test1') - self.xmpp2['jobs'].finishJob(self.pshost, 'testnode2', 'test2') - print result - #need to add check for update - - def test900cleanup(self): - "Cleaning up" - #self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode2'), "Could not delete test node.") - time.sleep(10) - - -if __name__ == '__main__': - #parse command line arguements - optp = OptionParser() - optp.add_option('-q','--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO) - optp.add_option('-d','--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) - optp.add_option('-v','--verbose', help='set logging to COMM', action='store_const', dest='loglevel', const=5, default=logging.INFO) - optp.add_option("-c","--config", dest="configfile", default="config.xml", help="set config file to use") - optp.add_option("-n","--nodenum", dest="nodenum", default="1", help="set node number to use") - optp.add_option("-p","--pubsub", dest="pubsub", default="1", help="set pubsub host to use") - opts,args = optp.parse_args() - - logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s') - - #load xml config - logging.info("Loading config file: %s" , opts.configfile) - config = configparser.RawConfigParser() - config.read(opts.configfile) - - #init - logging.info("Account 1 is %s" , config.get('account1', 'jid')) - xmpp1 = TestClient(config.get('account1','jid'), config.get('account1','pass')) - logging.info("Account 2 is %s" , config.get('account2', 'jid')) - xmpp2 = TestClient(config.get('account2','jid'), config.get('account2','pass')) - - xmpp1.registerPlugin('xep_0004') - xmpp1.registerPlugin('xep_0030') - xmpp1.registerPlugin('xep_0060') - xmpp1.registerPlugin('xep_0199') - xmpp1.registerPlugin('jobs') - xmpp2.registerPlugin('xep_0004') - xmpp2.registerPlugin('xep_0030') - xmpp2.registerPlugin('xep_0060') - xmpp2.registerPlugin('xep_0199') - xmpp2.registerPlugin('jobs') - - if not config.get('account1', 'server'): - # we don't know the server, but the lib can probably figure it out - xmpp1.connect() - else: - xmpp1.connect((config.get('account1', 'server'), 5222)) - xmpp1.process(threaded=True) - - #init - if not config.get('account2', 'server'): - # we don't know the server, but the lib can probably figure it out - xmpp2.connect() - else: - xmpp2.connect((config.get('account2', 'server'), 5222)) - xmpp2.process(threaded=True) - - TestPubsubServer.xmpp1 = xmpp1 - TestPubsubServer.xmpp2 = xmpp2 - TestPubsubServer.pshost = config.get('settings', 'pubsub') - xmpp1.waitforstart.get(True) - xmpp2.waitforstart.get(True) - testsuite = unittest.TestLoader().loadTestsFromTestCase(TestPubsubServer) - - alltests_suite = unittest.TestSuite([testsuite]) - result = unittest.TextTestRunner(verbosity=2).run(alltests_suite) - xmpp1.disconnect() - xmpp2.disconnect() diff --git a/conn_tests/test_pubsubserver.py b/conn_tests/test_pubsubserver.py deleted file mode 100644 index aae77dd3..00000000 --- a/conn_tests/test_pubsubserver.py +++ /dev/null @@ -1,233 +0,0 @@ -import logging -import sleekxmpp -from optparse import OptionParser -from xml.etree import cElementTree as ET -import os -import time -import sys -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: - import ConfigParser as configparser -try: - import queue -except ImportError: - import Queue as queue - -class TestClient(sleekxmpp.ClientXMPP): - def __init__(self, jid, password): - sleekxmpp.ClientXMPP.__init__(self, jid, password) - self.add_event_handler("session_start", self.start) - #self.add_event_handler("message", self.message) - self.waitforstart = queue.Queue() - - def start(self, event): - self.getRoster() - self.sendPresence() - self.waitforstart.put(True) - - -class TestPubsubServer(unittest.TestCase): - statev = {} - - def __init__(self, *args, **kwargs): - unittest.TestCase.__init__(self, *args, **kwargs) - - def setUp(self): - pass - - def test001getdefaultconfig(self): - """Get the default node config""" - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode2') - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode3') - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode4') - self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode5') - result = self.xmpp1['xep_0060'].getNodeConfig(self.pshost) - self.statev['defaultconfig'] = result - self.failUnless(isinstance(result, sleekxmpp.plugins.xep_0004.Form)) - - def test002createdefaultnode(self): - """Create a node without config""" - self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, 'testnode1')) - - def test003deletenode(self): - """Delete recently created node""" - self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode1')) - - def test004createnode(self): - """Create a node with a config""" - self.statev['defaultconfig'].field['pubsub#access_model'].setValue('open') - self.statev['defaultconfig'].field['pubsub#notify_retract'].setValue(True) - self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, 'testnode2', self.statev['defaultconfig'])) - - def test005reconfigure(self): - """Retrieving node config and reconfiguring""" - nconfig = self.xmpp1['xep_0060'].getNodeConfig(self.pshost, 'testnode2') - self.failUnless(nconfig, "No configuration returned") - #print("\n%s ==\n %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') - 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 w/ Account #2" - self.failUnless(self.xmpp2['xep_0060'].create_node(self.pshost, "testnode3", self.statev['defaultconfig'], True), "Could not create collection node") - - def test012subscribecollection(self): - "Subscribe Account #1 to collection" - self.failUnless(self.xmpp1['xep_0060'].subscribe(self.pshost, "testnode3")) - - def test013assignnodetocollection(self): - "Assign node to collection" - self.failUnless(self.xmpp2['xep_0060'].addNodeToCollection(self.pshost, 'testnode2', 'testnode3')) - - def test014publishcollection(self): - """Publishing item to collection child""" - item = ET.Element('{http://netflint.net/protocol/test}test') - w = Waiter('wait publish2', StanzaPath('message/pubsub_event/items@node=testnode2')) - self.xmpp1.registerHandler(w) - result = self.xmpp2['xep_0060'].setItem(self.pshost, "testnode2", (('test2', item),)) - msg = w.wait(5) # got to get a result in 5 seconds - self.failUnless(msg != False, "Account #1 did not get message event: perhaps node was advertised incorrectly?") - self.failUnless(result) - -# def test016speedtest(self): -# "Uncached speed test" -# import time -# start = time.time() -# for y in range(0, 50000, 1000): -# start2 = time.time() -# for x in range(y, y+1000): -# self.failUnless(self.xmpp1['xep_0060'].subscribe(self.pshost, "testnode4", subscribee="testuser%s@whatever" % x)) -# print time.time() - start2 -# seconds = time.time() - start -# print "--", seconds -# print "---------" -# time.sleep(15) -# self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode4'), "Could not delete non-cached test node") - -# def test015speedtest(self): -# "cached speed test" -# result = self.xmpp1['xep_0060'].getNodeConfig(self.pshost) -# self.statev['defaultconfig'] = result -# self.statev['defaultconfig'].field['pubsub#node_type'].setValue("leaf") -# self.statev['defaultconfig'].field['sleek#saveonchange'].setValue(True) -# self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, 'testnode4', self.statev['defaultconfig'])) -# self.statev['defaultconfig'].field['sleek#saveonchange'].setValue(False) -# self.failUnless(self.xmpp1['xep_0060'].create_node(self.pshost, 'testnode5', self.statev['defaultconfig'])) -# start = time.time() -# for y in range(0, 50000, 1000): -# start2 = time.time() -# for x in range(y, y+1000): -# self.failUnless(self.xmpp1['xep_0060'].subscribe(self.pshost, "testnode5", subscribee="testuser%s@whatever" % x)) -# print time.time() - start2 -# seconds = time.time() - start -# print "--", seconds - - def test900cleanup(self): - "Cleaning up" - self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode2'), "Could not delete test node.") - self.failUnless(self.xmpp1['xep_0060'].deleteNode(self.pshost, 'testnode3'), "Could not delete collection node") - - -if __name__ == '__main__': - #parse command line arguements - optp = OptionParser() - optp.add_option('-q','--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO) - optp.add_option('-d','--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) - optp.add_option('-v','--verbose', help='set logging to COMM', action='store_const', dest='loglevel', const=5, default=logging.INFO) - optp.add_option("-c","--config", dest="configfile", default="config.xml", help="set config file to use") - optp.add_option("-n","--nodenum", dest="nodenum", default="1", help="set node number to use") - optp.add_option("-p","--pubsub", dest="pubsub", default="1", help="set pubsub host to use") - opts,args = optp.parse_args() - - logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s') - - #load xml config - logging.info("Loading config file: %s" , opts.configfile) - config = configparser.RawConfigParser() - config.read(opts.configfile) - - #init - logging.info("Account 1 is %s" , config.get('account1', 'jid')) - xmpp1 = TestClient(config.get('account1','jid'), config.get('account1','pass')) - logging.info("Account 2 is %s" , config.get('account2', 'jid')) - xmpp2 = TestClient(config.get('account2','jid'), config.get('account2','pass')) - - xmpp1.registerPlugin('xep_0004') - xmpp1.registerPlugin('xep_0030') - xmpp1.registerPlugin('xep_0060') - xmpp1.registerPlugin('xep_0199') - xmpp2.registerPlugin('xep_0004') - xmpp2.registerPlugin('xep_0030') - xmpp2.registerPlugin('xep_0060') - xmpp2.registerPlugin('xep_0199') - - if not config.get('account1', 'server'): - # we don't know the server, but the lib can probably figure it out - xmpp1.connect() - else: - xmpp1.connect((config.get('account1', 'server'), 5222)) - xmpp1.process(threaded=True) - - #init - if not config.get('account2', 'server'): - # we don't know the server, but the lib can probably figure it out - xmpp2.connect() - else: - xmpp2.connect((config.get('account2', 'server'), 5222)) - xmpp2.process(threaded=True) - - TestPubsubServer.xmpp1 = xmpp1 - TestPubsubServer.xmpp2 = xmpp2 - TestPubsubServer.pshost = config.get('settings', 'pubsub') - xmpp1.waitforstart.get(True) - xmpp2.waitforstart.get(True) - testsuite = unittest.TestLoader().loadTestsFromTestCase(TestPubsubServer) - - alltests_suite = unittest.TestSuite([testsuite]) - result = unittest.TextTestRunner(verbosity=2).run(alltests_suite) - xmpp1.disconnect() - xmpp2.disconnect() diff --git a/conn_tests/testconfig.ini b/conn_tests/testconfig.ini deleted file mode 100644 index fc57bd17..00000000 --- a/conn_tests/testconfig.ini +++ /dev/null @@ -1,13 +0,0 @@ -[settings] -enabled=true -pubsub=pubsub.recon - -[account1] -jid=fritzy@recon -pass=testing123 -server= - -[account2] -jid=fritzy2@recon -pass=testing123 -server= diff --git a/conn_tests/testpubsub.py b/conn_tests/testpubsub.py deleted file mode 100755 index 0f46524e..00000000 --- a/conn_tests/testpubsub.py +++ /dev/null @@ -1,350 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2010 Nathanael C. Fritz - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -import logging -import sleekxmpp -from optparse import OptionParser -from xml.etree import cElementTree as ET -import os -import time -import sys -import Queue -import thread - - -class testps(sleekxmpp.ClientXMPP): - def __init__(self, jid, password, ssl=False, plugin_config = {}, plugin_whitelist=[], nodenum=0, pshost=None): - sleekxmpp.ClientXMPP.__init__(self, jid, password, ssl, plugin_config, plugin_whitelist) - self.registerPlugin('xep_0004') - self.registerPlugin('xep_0030') - self.registerPlugin('xep_0060') - self.registerPlugin('xep_0092') - self.add_handler("<message xmlns='jabber:client'><event xmlns='http://jabber.org/protocol/pubsub#event' /></message>", self.pubsubEventHandler, name='Pubsub Event', threaded=True) - self.add_event_handler("session_start", self.start, threaded=True) - self.add_handler("<iq type='error' />", self.handleError, name='Iq Error') - self.events = Queue.Queue() - self.default_config = None - self.ps = self.plugin['xep_0060'] - self.node = "pstestnode_%s" - self.pshost = pshost - if pshost is None: - self.pshost = self.boundjid.host - self.nodenum = int(nodenum) - self.leafnode = self.nodenum + 1 - self.collectnode = self.nodenum + 2 - self.lasterror = '' - self.sprintchars = 0 - self.defaultconfig = None - self.tests = ['test_defaultConfig', 'test_createDefaultNode', 'test_getNodes', 'test_deleteNode', 'test_createWithConfig', 'test_reconfigureNode', 'test_subscribeToNode', 'test_addItem', 'test_updateItem', 'test_deleteItem', 'test_unsubscribeNode', 'test_createCollection', 'test_subscribeCollection', 'test_addNodeCollection', 'test_deleteNodeCollection', 'test_addCollectionNode', 'test_deleteCollectionNode', 'test_unsubscribeNodeCollection', 'test_deleteCollection'] - self.passed = 0 - self.width = 120 - - def start(self, event): - #TODO: make this configurable - self.getRoster() - self.sendPresence(ppriority=20) - thread.start_new(self.test_all, tuple()) - - def sprint(self, msg, end=False, color=False): - length = len(msg) - if color: - if color == "red": - color = "1;31" - elif color == "green": - color = "0;32" - msg = "%s%s%s" % ("\033[%sm" % color, msg, "\033[0m") - if not end: - sys.stdout.write(msg) - self.sprintchars += length - else: - self.sprint("%s%s" % ("." * (self.width - self.sprintchars - length), msg)) - print('') - self.sprintchars = 0 - sys.stdout.flush() - - def pubsubEventHandler(self, xml): - for item in xml.findall('{http://jabber.org/protocol/pubsub#event}event/{http://jabber.org/protocol/pubsub#event}items/{http://jabber.org/protocol/pubsub#event}item'): - self.events.put(item.get('id', '__unknown__')) - for item in xml.findall('{http://jabber.org/protocol/pubsub#event}event/{http://jabber.org/protocol/pubsub#event}items/{http://jabber.org/protocol/pubsub#event}retract'): - self.events.put(item.get('id', '__unknown__')) - for item in xml.findall('{http://jabber.org/protocol/pubsub#event}event/{http://jabber.org/protocol/pubsub#event}collection/{http://jabber.org/protocol/pubsub#event}disassociate'): - self.events.put(item.get('node', '__unknown__')) - for item in xml.findall('{http://jabber.org/protocol/pubsub#event}event/{http://jabber.org/protocol/pubsub#event}collection/{http://jabber.org/protocol/pubsub#event}associate'): - self.events.put(item.get('node', '__unknown__')) - - def handleError(self, xml): - error = xml.find('{jabber:client}error') - self.lasterror = error.getchildren()[0].tag.split('}')[-1] - - def test_all(self): - print("Running Publish-Subscribe Tests") - version = self.plugin['xep_0092'].getVersion(self.pshost) - if version: - print("%s %s on %s" % (version.get('name', 'Unknown Server'), version.get('version', 'v?'), version.get('os', 'Unknown OS'))) - print("=" * self.width) - for test in self.tests: - testfunc = getattr(self, test) - self.sprint("%s" % testfunc.__doc__) - if testfunc(): - self.sprint("Passed", True, "green") - self.passed += 1 - else: - if not self.lasterror: - self.lasterror = 'No response' - self.sprint("Failed (%s)" % self.lasterror, True, "red") - self.lasterror = '' - print("=" * self.width) - self.sprint("Cleaning up...") - #self.ps.deleteNode(self.pshost, self.node % self.nodenum) - self.ps.deleteNode(self.pshost, self.node % self.leafnode) - #self.ps.deleteNode(self.pshost, self.node % self.collectnode) - self.sprint("Done", True, "green") - self.disconnect() - self.sprint("%s" % self.passed, False, "green") - self.sprint("/%s Passed -- " % len(self.tests)) - if len(self.tests) - self.passed: - self.sprint("%s" % (len(self.tests) - self.passed), False, "red") - else: - self.sprint("%s" % (len(self.tests) - self.passed), False, "green") - self.sprint(" Failed Tests") - print - #print "%s/%s Passed -- %s Failed Tests" % (self.passed, len(self.tests), len(self.tests) - self.passed) - - def test_defaultConfig(self): - "Retreiving default configuration" - result = self.ps.getNodeConfig(self.pshost) - if result is False or result is None: - return False - else: - self.defaultconfig = result - try: - self.defaultconfig.field['pubsub#access_model'].setValue('open') - except KeyError: - pass - try: - self.defaultconfig.field['pubsub#notify_retract'].setValue(True) - except KeyError: - pass - return True - - def test_createDefaultNode(self): - "Creating default node" - return self.ps.create_node(self.pshost, self.node % self.nodenum) - - def test_getNodes(self): - "Getting list of nodes" - self.ps.getNodes(self.pshost) - self.ps.getItems(self.pshost, 'blog') - return True - - def test_deleteNode(self): - "Deleting node" - return self.ps.deleteNode(self.pshost, self.node % self.nodenum) - - def test_createWithConfig(self): - "Creating node with config" - if self.defaultconfig is None: - self.lasterror = "No Avail Config" - return False - return self.ps.create_node(self.pshost, self.node % self.leafnode, self.defaultconfig) - - def test_reconfigureNode(self): - "Retrieving node config and reconfiguring" - nconfig = self.ps.getNodeConfig(self.pshost, self.node % self.leafnode) - if nconfig == False: - return False - return self.ps.setNodeConfig(self.pshost, self.node % self.leafnode, nconfig) - - def test_subscribeToNode(self): - "Subscribing to node" - return self.ps.subscribe(self.pshost, self.node % self.leafnode) - - def test_addItem(self): - "Adding item, waiting for notification" - item = ET.Element('test') - result = self.ps.setItem(self.pshost, self.node % self.leafnode, (('test_node1', item),)) - if result == False: - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - return False - if event == 'test_node1': - return True - return False - - def test_updateItem(self): - "Updating item, waiting for notification" - item = ET.Element('test') - item.attrib['crap'] = 'yup, right here' - result = self.ps.setItem(self.pshost, self.node % self.leafnode, (('test_node1', item),)) - if result == False: - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - return False - if event == 'test_node1': - return True - return False - - def test_deleteItem(self): - "Deleting item, waiting for notification" - result = self.ps.deleteItem(self.pshost, self.node % self.leafnode, 'test_node1') - if result == False: - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - self.lasterror = "No Notification" - return False - if event == 'test_node1': - return True - return False - - def test_unsubscribeNode(self): - "Unsubscribing from node" - return self.ps.unsubscribe(self.pshost, self.node % self.leafnode) - - def test_createCollection(self): - "Creating collection node" - return self.ps.create_node(self.pshost, self.node % self.collectnode, self.defaultconfig, True) - - def test_subscribeCollection(self): - "Subscribing to collection node" - return self.ps.subscribe(self.pshost, self.node % self.collectnode) - - def test_addNodeCollection(self): - "Assigning node to collection, waiting for notification" - config = self.ps.getNodeConfig(self.pshost, self.node % self.leafnode) - if not config or config is None: - self.lasterror = "Config Error" - return False - try: - config.field['pubsub#collection'].setValue(self.node % self.collectnode) - except KeyError: - self.sprint("...Missing Field...", False, "red") - config.addField('pubsub#collection', value=self.node % self.collectnode) - if not self.ps.setNodeConfig(self.pshost, self.node % self.leafnode, config): - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - self.lasterror = "No Notification" - return False - if event == self.node % self.leafnode: - return True - return False - - def test_deleteNodeCollection(self): - "Removing node assignment to collection, waiting for notification" - config = self.ps.getNodeConfig(self.pshost, self.node % self.leafnode) - if not config or config is None: - self.lasterror = "Config Error" - return False - try: - config.field['pubsub#collection'].delValue(self.node % self.collectnode) - except KeyError: - self.sprint("...Missing Field...", False, "red") - config.addField('pubsub#collection', value='') - if not self.ps.setNodeConfig(self.pshost, self.node % self.leafnode, config): - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - self.lasterror = "No Notification" - return False - if event == self.node % self.leafnode: - return True - return False - - def test_addCollectionNode(self): - "Assigning node from collection, waiting for notification" - config = self.ps.getNodeConfig(self.pshost, self.node % self.collectnode) - if not config or config is None: - self.lasterror = "Config Error" - return False - try: - config.field['pubsub#children'].setValue(self.node % self.leafnode) - except KeyError: - self.sprint("...Missing Field...", False, "red") - config.addField('pubsub#children', value=self.node % self.leafnode) - if not self.ps.setNodeConfig(self.pshost, self.node % self.collectnode, config): - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - self.lasterror = "No Notification" - return False - if event == self.node % self.leafnode: - return True - return False - - def test_deleteCollectionNode(self): - "Removing node from collection, waiting for notification" - config = self.ps.getNodeConfig(self.pshost, self.node % self.collectnode) - if not config or config is None: - self.lasterror = "Config Error" - return False - try: - config.field['pubsub#children'].delValue(self.node % self.leafnode) - except KeyError: - self.sprint("...Missing Field...", False, "red") - config.addField('pubsub#children', value='') - if not self.ps.setNodeConfig(self.pshost, self.node % self.collectnode, config): - return False - try: - event = self.events.get(True, 10) - except Queue.Empty: - self.lasterror = "No Notification" - return False - if event == self.node % self.leafnode: - return True - return False - - def test_unsubscribeNodeCollection(self): - "Unsubscribing from collection" - return self.ps.unsubscribe(self.pshost, self.node % self.collectnode) - - def test_deleteCollection(self): - "Deleting collection" - return self.ps.deleteNode(self.pshost, self.node % self.collectnode) - -if __name__ == '__main__': - #parse command line arguements - optp = OptionParser() - optp.add_option('-q','--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO) - optp.add_option('-d','--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) - optp.add_option('-v','--verbose', help='set logging to COMM', action='store_const', dest='loglevel', const=5, default=logging.INFO) - optp.add_option("-c","--config", dest="configfile", default="config.xml", help="set config file to use") - optp.add_option("-n","--nodenum", dest="nodenum", default="1", help="set node number to use") - optp.add_option("-p","--pubsub", dest="pubsub", default="1", help="set pubsub host to use") - opts,args = optp.parse_args() - - logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s') - - #load xml config - logging.info("Loading config file: %s" , opts.configfile) - config = ET.parse(os.path.expanduser(opts.configfile)).find('auth') - - #init - logging.info("Logging in as %s" , config.attrib['jid']) - - - plugin_config = {} - plugin_config['xep_0092'] = {'name': 'SleekXMPP Example', 'version': '0.1-dev'} - plugin_config['xep_0199'] = {'keepalive': True, 'timeout': 30, 'frequency': 300} - - con = testps(config.attrib['jid'], config.attrib['pass'], plugin_config=plugin_config, plugin_whitelist=[], nodenum=opts.nodenum, pshost=opts.pubsub) - if not config.get('server', None): - # we don't know the server, but the lib can probably figure it out - con.connect() - else: - con.connect((config.attrib['server'], 5222)) - con.process(threaded=False) - print("") |