A fork of https://github.com/Synerty/SOAPpy-py3 This is a working tree till fixes get imported upstream.
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.
 
 
 
 

113 lines
4.8 KiB

  1. #!/usr/bin/env python
  2. import unittest
  3. import os, re
  4. import sys
  5. sys.path.insert (1, '..')
  6. import SOAPpy
  7. ident = '$Id: testWSDL.py,v 1.2 2003/05/09 12:46:11 warnes Exp $'
  8. # Check for a web proxy definition in environment
  9. try:
  10. proxy_url=os.environ['http_proxy']
  11. phost, pport = re.search('http://([^:]+):([0-9]+)', proxy_url).group(1,2)
  12. http_proxy = "%s:%s" % (phost, pport)
  13. except:
  14. http_proxy = None
  15. class IntegerArithmenticTestCase(unittest.TestCase):
  16. def setUp(self):
  17. self.wsdlstr1 = '''<?xml version="1.0"?>
  18. <definitions name="TemperatureService" targetNamespace="http://www.xmethods.net/sd/TemperatureService.wsdl" xmlns:tns="http://www.xmethods.net/sd/TemperatureService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
  19. <message name="getTempRequest">
  20. <part name="zipcode" type="xsd:string"/>
  21. </message>
  22. <message name="getTempResponse">
  23. <part name="return" type="xsd:float"/>
  24. </message>
  25. <portType name="TemperaturePortType">
  26. <operation name="getTemp">
  27. <input message="tns:getTempRequest"/>
  28. <output message="tns:getTempResponse"/>
  29. </operation>
  30. </portType>
  31. <binding name="TemperatureBinding" type="tns:TemperaturePortType">
  32. <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  33. <operation name="getTemp">
  34. <soap:operation soapAction=""/>
  35. <input>
  36. <soap:body use="encoded" namespace="urn:xmethods-Temperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  37. </input>
  38. <output>
  39. <soap:body use="encoded" namespace="urn:xmethods-Temperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  40. </output>
  41. </operation>
  42. </binding>
  43. <service name="TemperatureService">
  44. <documentation>Returns current temperature in a given U.S. zipcode </documentation>
  45. <port name="TemperaturePort" binding="tns:TemperatureBinding">
  46. <soap:address location="http://services.xmethods.net:80/soap/servlet/rpcrouter"/>
  47. </port>
  48. </service>
  49. </definitions>
  50. '''
  51. def testParseWsdlString(self):
  52. '''Parse XMethods TemperatureService wsdl from a string.'''
  53. wsdl = SOAPpy.WSDL.Proxy(self.wsdlstr1, http_proxy=http_proxy)
  54. self.assertEquals(len(wsdl.methods), 1)
  55. method = wsdl.methods.values()[0]
  56. self.assertEquals(method.methodName, 'getTemp')
  57. self.assertEquals(method.namespace, 'urn:xmethods-Temperature')
  58. self.assertEquals(method.location,
  59. 'http://services.xmethods.net:80/soap/servlet/rpcrouter')
  60. def testParseWsdlFile(self):
  61. '''Parse XMethods TemperatureService wsdl from a file.'''
  62. # figure out path to the test directory
  63. dir = os.path.abspath('.')
  64. fname = './TemperatureService.wsdl'
  65. try:
  66. f = file(fname)
  67. except (IOError, OSError):
  68. self.assert_(0, 'Cound not find wsdl file "%s"' % file)
  69. wsdl = SOAPpy.WSDL.Proxy(fname, http_proxy=http_proxy)
  70. self.assertEquals(len(wsdl.methods), 1)
  71. method = wsdl.methods.values()[0]
  72. self.assertEquals(method.methodName, 'getTemp')
  73. self.assertEquals(method.namespace, 'urn:xmethods-Temperature')
  74. self.assertEquals(method.location,
  75. 'http://services.xmethods.net:80/soap/servlet/rpcrouter')
  76. def testParseWsdlUrl(self):
  77. '''Parse XMethods TemperatureService wsdl from a url.'''
  78. wsdl = SOAPpy.WSDL.Proxy('http://www.xmethods.net/sd/2001/TemperatureService.wsdl', http_proxy=http_proxy)
  79. self.assertEquals(len(wsdl.methods), 1)
  80. method = wsdl.methods.values()[0]
  81. self.assertEquals(method.methodName, 'getTemp')
  82. self.assertEquals(method.namespace, 'urn:xmethods-Temperature')
  83. self.assertEquals(method.location,
  84. 'http://services.xmethods.net:80/soap/servlet/rpcrouter')
  85. def testGetTemp(self):
  86. '''Parse TemperatureService and call getTemp.'''
  87. zip = '01072'
  88. proxy = SOAPpy.WSDL.Proxy(self.wsdlstr1, http_proxy=http_proxy)
  89. temp = proxy.getTemp(zip)
  90. print 'Temperature at', zip, 'is', temp
  91. if __name__ == '__main__':
  92. unittest.main()