You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

138 lines
4.5 KiB

  1. #!/usr/bin/env python
  2. import unittest, sys
  3. from ConfigParser import NoOptionError
  4. from ZSI.wstools.WSDLTools import WSDLReader
  5. from ZSI.wstools.Utility import DOM
  6. CONFIG = None
  7. NETWORK = 'services_by_http'
  8. STANDALONE = 'services_by_file'
  9. class WSDLToolsTestCase(unittest.TestCase):
  10. def __init__(self, methodName='runTest'):
  11. unittest.TestCase.__init__(self, methodName)
  12. def setUp(self):
  13. pass
  14. def tearDown(self):
  15. if self.wsdl:
  16. self.wsdlServices()
  17. self.wsdlMessages()
  18. self.wsdlPortTypes()
  19. self.wsdlBindings()
  20. self.wsdlImports()
  21. self.wsdlExtensions()
  22. self.wsdlTypes()
  23. def loadFromConfig(self, config=CONFIG):
  24. self.wsdl = None
  25. try:
  26. path = config.get(self.section, self.option)
  27. except NoOptionError, ex:
  28. pass
  29. else:
  30. if path[:7] == 'http://':
  31. self.loadFromURL(url=path)
  32. else:
  33. self.loadFromFile(file=path)
  34. def loadFromFile(self, file):
  35. self.wsdl = WSDLReader().loadFromFile(file)
  36. def loadFromURL(self, url):
  37. self.wsdl = WSDLReader().loadFromURL(url)
  38. def checkWSDLCollection(self, tag_name, component, key='name'):
  39. definition = self.wsdl.document.documentElement
  40. version = DOM.WSDLUriToVersion(definition.namespaceURI)
  41. nspname = DOM.GetWSDLUri(version)
  42. for node in DOM.getElements(definition, tag_name, nspname):
  43. name = DOM.getAttr(node, key)
  44. comp = component[name]
  45. self.failUnlessEqual(eval('comp.%s' %key), name)
  46. def checkXSDCollection(self, tag_name, component, node, key='name'):
  47. for cnode in DOM.getElements(node, tag_name):
  48. name = DOM.getAttr(cnode, key)
  49. component[name]
  50. def wsdlServices(self):
  51. self.checkWSDLCollection('service', self.wsdl.services)
  52. def wsdlMessages(self):
  53. self.checkWSDLCollection('message', self.wsdl.messages)
  54. def wsdlPortTypes(self):
  55. self.checkWSDLCollection('portType', self.wsdl.portTypes)
  56. def wsdlBindings(self):
  57. self.checkWSDLCollection('binding', self.wsdl.bindings)
  58. def wsdlImports(self):
  59. self.checkWSDLCollection('import', self.wsdl.imports, key='namespace')
  60. def wsdlTypes(self):
  61. for key in self.wsdl.types.keys():
  62. schema = self.wsdl.types[key]
  63. self.failUnlessEqual(key, schema.getTargetNamespace())
  64. definition = self.wsdl.document.documentElement
  65. version = DOM.WSDLUriToVersion(definition.namespaceURI)
  66. nspname = DOM.GetWSDLUri(version)
  67. for node in DOM.getElements(definition, 'types', nspname):
  68. for snode in DOM.getElements(node, 'schema'):
  69. tns = DOM.findTargetNS(snode)
  70. schema = self.wsdl.types[tns]
  71. self.schemaAttributesDeclarations(schema, snode)
  72. self.schemaAttributeGroupDeclarations(schema, snode)
  73. self.schemaElementDeclarations(schema, snode)
  74. self.schemaTypeDefinitions(schema, snode)
  75. def wsdlExtensions(self):
  76. if self.wsdl.extensions:
  77. print 'No check for WSDLTools(%s) Extensions:' %(self.wsdl.name)
  78. for ext in self.wsdl.extensions: print '\t', ext
  79. def schemaAttributesDeclarations(self, schema, node):
  80. self.checkXSDCollection('attribute', schema.attr_decl, node)
  81. def schemaAttributeGroupDeclarations(self, schema, node):
  82. self.checkXSDCollection('group', schema.attr_groups, node)
  83. def schemaElementDeclarations(self, schema, node):
  84. self.checkXSDCollection('element', schema.elements, node)
  85. def schemaTypeDefinitions(self, schema, node):
  86. self.checkXSDCollection('complexType', schema.types, node)
  87. self.checkXSDCollection('simpleType', schema.types, node)
  88. def makeNetworkSuite():
  89. return getSuite(section='services_by_http')
  90. def makeStandAloneSuite():
  91. return getSuite('services_by_file')
  92. def getSuite(section):
  93. names = CONFIG.options(section)
  94. tests = []
  95. suite = unittest.TestSuite()
  96. loader = unittest.TestLoader()
  97. WSDLToolsTestCase.section = section
  98. for case in [WSDLToolsTestCase,]:
  99. case.section = section
  100. test = loader.loadTestsFromTestCase(case)
  101. tests.append(test)
  102. #tests.sort()
  103. suite.addTests(tests)
  104. return suite
  105. #makeTestSuite = makeStandAloneSuite
  106. #def main():
  107. # unittest.main(defaultTest="makeTestSuite")
  108. if __name__ == "__main__" : main()