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.
 
 
 

101 lines
3.0 KiB

  1. ############################################################################
  2. # David W. Robertson, LBNL
  3. # See Copyright for copyright notice!
  4. ###########################################################################
  5. import sys, ConfigParser, unittest
  6. import StringIO
  7. from ZSI import wsdl2python
  8. from ZSI.wstools.WSDLTools import WSDLReader
  9. import utils
  10. """
  11. Unittest for the wsdl2python class
  12. """
  13. def setUpWsdl(path):
  14. if path[:7] == 'http://':
  15. wsdl = WSDLReader().loadFromURL(path)
  16. else:
  17. wsdl = WSDLReader().loadFromFile(path)
  18. return wsdl
  19. class Wsdl2pythonTest(unittest.TestCase):
  20. """Test case for wsdl2python.WriteServiceModule
  21. """
  22. def __init__(self, methodName='runTest'):
  23. global configLoader
  24. unittest.TestCase.__init__(self, methodName)
  25. def setUp(self):
  26. # not thread safe
  27. self.path = configLoader.nameGenerator.next()
  28. print self.path
  29. sys.stdout.flush()
  30. self.testdiff = utils.TestDiff(self)
  31. self.wsdl = configLoader.nameGenerator.next()
  32. def tearDown(self):
  33. if self.wsdl is not None:
  34. del self.wsdl
  35. self.testdiff.close()
  36. def __str__(self):
  37. teststr = unittest.TestCase.__str__(self)
  38. if hasattr(self, "path"):
  39. return "%s: %s" % (teststr, self.path )
  40. else:
  41. return "%s" % (teststr)
  42. def do_diffs(self, choice):
  43. self.failUnless(self.wsdl is not None, "Unable to start, load failed")
  44. codegen = wsdl2python.WriteServiceModule(self.wsdl)
  45. f_types, f_services = codegen.get_module_names()
  46. strFile = StringIO.StringIO()
  47. if choice == "service_types":
  48. self.testdiff.setDiffFile(f_types + ".py")
  49. codegen.write_service_types(f_types, strFile)
  50. else:
  51. self.testdiff.setDiffFile(f_services + ".py")
  52. codegen.write_services(f_types, f_services, strFile)
  53. self.testdiff.failUnlessEqual(strFile)
  54. strFile.close()
  55. def test_Xmethods_service_types(self):
  56. # add exception for url not found
  57. self.do_diffs("service_types")
  58. def test_Xmethods_services(self):
  59. self.do_diffs("services")
  60. def makeTestSuite(topLevel=False, config=None):
  61. global configLoader
  62. suite = unittest.TestSuite()
  63. if not hasattr(sys.modules[__name__], "configLoader"):
  64. if not config:
  65. configLoader = utils.MatchTestLoader(False, "config.py",
  66. "Wsdl2pythonTest")
  67. else:
  68. configLoader = config
  69. configLoader.testMethodPrefix = "test"
  70. suite.addTest(configLoader.loadTestsFromConfig(Wsdl2pythonTest,
  71. "services_by_http",
  72. valueFunc = setUpWsdl))
  73. return suite
  74. def main():
  75. global configLoader
  76. configLoader = utils.MatchTestLoader(False, "config.py", "makeTestSuite")
  77. unittest.main(defaultTest="makeTestSuite", testLoader=configLoader)
  78. if __name__ == "__main__" : main()