Added Files:
README config.py schema.tar.gz test_t1.py test_wsdl.py
test_wstools.py test_wstools_net.py xmethods.tar.gz
-- basic unittesting framework for WSDLTools/XMLSchema,
test_t1 just checks that everything goes where it's supposed to.
----------------------------------------------------------------------
main
| @@ -0,0 +1,30 @@ | |||||
| Two top level modules have been provided to run the tests. "test_wstools.py" is used | |||||
| to run all of the local tests. "test_wstools_net.py" is used to run all of the | |||||
| tests that require network access. | |||||
| TESTS: | |||||
| test_t1 -- Basic test, just checks that wsdl and xsd objects are in the | |||||
| right places. | |||||
| CONTENTS OF SAMPLE WSDL/XSD: | |||||
| schema -- Taken from globus-3.0.1(http://www.globus.org) | |||||
| xmethods -- Taken from XMethods(http://www.xmethods.com) | |||||
| airport.wsdl | |||||
| AmazonWebServices.wsdl | |||||
| books.wsdl | |||||
| Distance.wsdl | |||||
| freedb.wsdl | |||||
| globalweather.wsdl | |||||
| IHaddock.wsdl | |||||
| ip2geo.wsdl | |||||
| magic.wsdl | |||||
| query.wsdl | |||||
| RateInfo.wsdl | |||||
| SHA1Encrypt.wsdl | |||||
| siteInspect.wsdl | |||||
| TemperatureService.wsdl | |||||
| usweather.wsdl | |||||
| zip2geo.wsdl | |||||
| @@ -0,0 +1,51 @@ | |||||
| ############################################################################ | |||||
| # Joshua R. Boverhof, LBNL | |||||
| # See Copyright for copyright notice! | |||||
| ########################################################################### | |||||
| ########################################################################### | |||||
| # Config file for the unit test framework. | |||||
| # Sections below. | |||||
| ########################################################################### | |||||
| ########################################################################## | |||||
| # SECTION [files] - archives of wsdl/xsd files. | |||||
| # | |||||
| ########################################################################## | |||||
| [files] | |||||
| archives = ('xmethods.tar.gz', 'schema.tar.gz') | |||||
| ########################################################################## | |||||
| # SECTION [services_by_file] - all services locally available for | |||||
| # testing. | |||||
| ########################################################################## | |||||
| [services_by_file] | |||||
| ogsi = schema/ogsi/ogsi_service.wsdl | |||||
| airport = xmethods/airport.wsdl | |||||
| amazon = xmethods/AmazonWebServices.wsdl | |||||
| books = xmethods/books.wsdl | |||||
| distance = xmethods/Distance.wsdl | |||||
| freedb = xmethods/freedb.wsdl | |||||
| globalweather = xmethods/globalweather.wsdl | |||||
| IHaddock = xmethods/IHaddock.wsdl | |||||
| ip2geo = xmethods/ip2geo.wsdl | |||||
| magic = xmethods/magic.wsdl | |||||
| query = xmethods/query.wsdl | |||||
| RateInfo = xmethods/RateInfo.wsdl | |||||
| SHA1Encrypt = xmethods/SHA1Encrypt.wsdl | |||||
| siteInsepct = xmethods/siteInspect.wsdl | |||||
| TemperatureService = xmethods/TemperatureService.wsdl | |||||
| usweather = xmethods/usweather.wsdl | |||||
| zip2geo = xmethods/zip2geo.wsdl | |||||
| ########################################################################## | |||||
| # SECTION [services_by_http] - all services available for | |||||
| # network testing. | |||||
| ########################################################################## | |||||
| [services_by_http] | |||||
| amazon = http://soap.amazon.com/schemas/AmazonWebServices.wsdl | |||||
| homelandsecurity = http://www.boyzoid.com/threat.cfc?wsdl | |||||
| rtf2html = http://www.infoaccelerator.net/cfc/rft2html.cfc?WSDL | |||||
| @@ -0,0 +1,49 @@ | |||||
| #!/usr/bin/env python | |||||
| import unittest, sys | |||||
| from ConfigParser import ConfigParser | |||||
| from ZSI.wstools.WSDLTools import WSDLReader | |||||
| from test_wsdl import WSDLToolsTestCase, NETWORK, STANDALONE | |||||
| CONFIG = None | |||||
| class AmazonTestCase(WSDLToolsTestCase): | |||||
| def test(self): | |||||
| self.option = 'amazon' | |||||
| self.loadFromConfig(CONFIG) | |||||
| class AirportTestCase(WSDLToolsTestCase): | |||||
| def test(self): | |||||
| self.option = 'airport' | |||||
| self.loadFromConfig(CONFIG) | |||||
| class OGSITestCase(WSDLToolsTestCase): | |||||
| def test(self): | |||||
| self.option = 'ogsi' | |||||
| self.loadFromConfig(CONFIG) | |||||
| CASES = [AmazonTestCase, AirportTestCase, OGSITestCase] | |||||
| def makeNetworkSuite(): | |||||
| return getSuite(NETWORK) | |||||
| def makeStandAloneSuite(): | |||||
| return getSuite(STANDALONE) | |||||
| def getSuite(section): | |||||
| tests = [] | |||||
| suite = unittest.TestSuite() | |||||
| loader = unittest.TestLoader() | |||||
| for case in CASES: | |||||
| case.section = section | |||||
| test = loader.loadTestsFromTestCase(case) | |||||
| tests.append(test) | |||||
| suite.addTests(tests) | |||||
| return suite | |||||
| def main(): | |||||
| global CONFIG | |||||
| from test_wstools import CONFIG_FILE | |||||
| CONFIG = ConfigParser() | |||||
| CONFIG.read(CONFIG_FILE) | |||||
| unittest.TestProgram(defaultTest='makeStandAloneSuite') | |||||
| if __name__ == "__main__" : main() | |||||
| @@ -0,0 +1,137 @@ | |||||
| #!/usr/bin/env python | |||||
| import unittest, sys | |||||
| from ConfigParser import NoOptionError | |||||
| from ZSI.wstools.WSDLTools import WSDLReader | |||||
| from ZSI.wstools.Utility import DOM | |||||
| CONFIG = None | |||||
| NETWORK = 'services_by_http' | |||||
| STANDALONE = 'services_by_file' | |||||
| class WSDLToolsTestCase(unittest.TestCase): | |||||
| def __init__(self, methodName='runTest'): | |||||
| unittest.TestCase.__init__(self, methodName) | |||||
| def setUp(self): | |||||
| pass | |||||
| def tearDown(self): | |||||
| if self.wsdl: | |||||
| self.wsdlServices() | |||||
| self.wsdlMessages() | |||||
| self.wsdlPortTypes() | |||||
| self.wsdlBindings() | |||||
| self.wsdlImports() | |||||
| self.wsdlExtensions() | |||||
| self.wsdlTypes() | |||||
| def loadFromConfig(self, config=CONFIG): | |||||
| try: | |||||
| print config | |||||
| path = config.get(self.section, self.option) | |||||
| except NoOptionError, ex: | |||||
| self.wsdl = None | |||||
| else: | |||||
| if path[:7] == 'http://': | |||||
| self.loadFromURL(url=path) | |||||
| else: | |||||
| self.loadFromFile(file=path) | |||||
| def loadFromFile(self, file): | |||||
| self.wsdl = WSDLReader().loadFromFile(file) | |||||
| def loadFromURL(self, url): | |||||
| self.wsdl = WSDLReader().loadFromURL(url) | |||||
| def checkWSDLCollection(self, tag_name, component, key='name'): | |||||
| definition = self.wsdl.document.documentElement | |||||
| version = DOM.WSDLUriToVersion(definition.namespaceURI) | |||||
| nspname = DOM.GetWSDLUri(version) | |||||
| for node in DOM.getElements(definition, tag_name, nspname): | |||||
| name = DOM.getAttr(node, key) | |||||
| comp = component[name] | |||||
| self.failUnlessEqual(eval('comp.%s' %key), name) | |||||
| def checkXSDCollection(self, tag_name, component, node, key='name'): | |||||
| for cnode in DOM.getElements(node, tag_name): | |||||
| name = DOM.getAttr(cnode, key) | |||||
| component[name] | |||||
| def wsdlServices(self): | |||||
| self.checkWSDLCollection('service', self.wsdl.services) | |||||
| def wsdlMessages(self): | |||||
| self.checkWSDLCollection('message', self.wsdl.messages) | |||||
| def wsdlPortTypes(self): | |||||
| self.checkWSDLCollection('portType', self.wsdl.portTypes) | |||||
| def wsdlBindings(self): | |||||
| self.checkWSDLCollection('binding', self.wsdl.bindings) | |||||
| def wsdlImports(self): | |||||
| self.checkWSDLCollection('import', self.wsdl.imports, key='namespace') | |||||
| def wsdlTypes(self): | |||||
| for key in self.wsdl.types.keys(): | |||||
| schema = self.wsdl.types[key] | |||||
| self.failUnlessEqual(key, schema.getTargetNamespace()) | |||||
| definition = self.wsdl.document.documentElement | |||||
| version = DOM.WSDLUriToVersion(definition.namespaceURI) | |||||
| nspname = DOM.GetWSDLUri(version) | |||||
| for node in DOM.getElements(definition, 'types', nspname): | |||||
| for snode in DOM.getElements(node, 'schema'): | |||||
| tns = DOM.findTargetNS(snode) | |||||
| schema = self.wsdl.types[tns] | |||||
| self.schemaAttributesDeclarations(schema, snode) | |||||
| self.schemaAttributeGroupDeclarations(schema, snode) | |||||
| self.schemaElementDeclarations(schema, snode) | |||||
| self.schemaTypeDefinitions(schema, snode) | |||||
| def wsdlExtensions(self): | |||||
| if self.wsdl.extensions: | |||||
| print 'No check for WSDLTools(%s) Extensions:' %(self.wsdl.name) | |||||
| for ext in self.wsdl.extensions: print '\t', ext | |||||
| def schemaAttributesDeclarations(self, schema, node): | |||||
| self.checkXSDCollection('attribute', schema.attr_decl, node) | |||||
| def schemaAttributeGroupDeclarations(self, schema, node): | |||||
| self.checkXSDCollection('group', schema.attr_groups, node) | |||||
| def schemaElementDeclarations(self, schema, node): | |||||
| self.checkXSDCollection('element', schema.elements, node) | |||||
| def schemaTypeDefinitions(self, schema, node): | |||||
| self.checkXSDCollection('complexType', schema.types, node) | |||||
| self.checkXSDCollection('simpleType', schema.types, node) | |||||
| def makeNetworkSuite(): | |||||
| return getSuite(section='services_by_http') | |||||
| def makeStandAloneSuite(): | |||||
| return getSuite('services_by_file') | |||||
| def getSuite(section): | |||||
| names = CONFIG.options(section) | |||||
| tests = [] | |||||
| suite = unittest.TestSuite() | |||||
| loader = unittest.TestLoader() | |||||
| WSDLToolsTestCase.section = section | |||||
| for case in [WSDLToolsTestCase,]: | |||||
| case.section = section | |||||
| test = loader.loadTestsFromTestCase(case) | |||||
| tests.append(test) | |||||
| #tests.sort() | |||||
| suite.addTests(tests) | |||||
| return suite | |||||
| #makeTestSuite = makeStandAloneSuite | |||||
| #def main(): | |||||
| # unittest.main(defaultTest="makeTestSuite") | |||||
| if __name__ == "__main__" : main() | |||||
| @@ -0,0 +1,23 @@ | |||||
| #!/usr/bin/env python | |||||
| import unittest, tarfile, os, ConfigParser | |||||
| import test_t1 | |||||
| SECTION='files' | |||||
| CONFIG_FILE = 'config.py' | |||||
| def main(): | |||||
| config = ConfigParser.ConfigParser() | |||||
| config.read(CONFIG_FILE) | |||||
| archives = config.get(SECTION, 'archives') | |||||
| archives = eval(archives) | |||||
| test_t1.CONFIG = config | |||||
| for file in archives: | |||||
| tar = tarfile.open(file) | |||||
| if not os.access(tar.membernames[0], os.R_OK): | |||||
| for i in tar.getnames(): | |||||
| tar.extract(i) | |||||
| unittest.TestProgram(defaultTest='test_t1.makeStandAloneSuite') | |||||
| if __name__ == "__main__" : main() | |||||
| @@ -0,0 +1,14 @@ | |||||
| #!/usr/bin/env python | |||||
| import unittest, tarfile, os, ConfigParser | |||||
| import test_t1 | |||||
| CONFIG_FILE = 'config.py' | |||||
| def main(): | |||||
| config = ConfigParser.ConfigParser() | |||||
| config.read(CONFIG_FILE) | |||||
| test_t1.CONFIG = config | |||||
| unittest.TestProgram(defaultTest='test_t1.makeNetworkSuite') | |||||
| if __name__ == "__main__" : main() | |||||