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.
 
 
 
 

148 lines
4.2 KiB

  1. #!/usr/bin/env python
  2. import sys, unittest
  3. sys.path.insert(1, "..")
  4. from SOAPpy import *
  5. Config.debug=1
  6. class ClientTestCase(unittest.TestCase):
  7. def testParseRules(self):
  8. x = """<?xml version="1.0" encoding="utf-8"?>
  9. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  10. xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  11. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  12. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  13. <soap:Body
  14. soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  15. <SomeMethod>
  16. <Result>
  17. <Book>
  18. <title>My Life and Work</title>
  19. </Book>
  20. <Person>
  21. <name>Henry Ford</name>
  22. <age> 49 </age>
  23. <height> 5.5 </height>
  24. </Person>
  25. </Result>
  26. </SomeMethod>
  27. </soap:Body>
  28. </soap:Envelope>
  29. """
  30. def negfloat(x):
  31. return float(x) * -1.0
  32. # parse rules
  33. pr = {'SomeMethod':
  34. {'Result':
  35. {
  36. 'Book': {'title':'string'},
  37. 'Person': {'age':'int',
  38. 'height':negfloat}
  39. }
  40. }
  41. }
  42. y = parseSOAPRPC(x, rules=pr)
  43. assert y.Result.Person.age == 49
  44. assert y.Result.Person.height == -5.5
  45. x = '''<SOAP-ENV:Envelope
  46. SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  47. xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  48. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  49. xmlns:xsd="http://www.w3.org/1999/XMLSchema"
  50. xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
  51. <SOAP-ENV:Body>
  52. <Bounds>
  53. <param>
  54. <item>12</item>
  55. <item>23</item>
  56. <item>0</item>
  57. <item>-31</item>
  58. </param>
  59. <param1 xsi:null="1"></param1>
  60. </Bounds>
  61. </SOAP-ENV:Body>
  62. </SOAP-ENV:Envelope>
  63. '''
  64. # parse rules
  65. pr = {'Bounds':
  66. {'param': 'arrayType=string[]',
  67. }
  68. }
  69. pr2 = {'Bounds':
  70. {'param': 'arrayType=int[4]',
  71. }
  72. }
  73. y = parseSOAPRPC(x, rules=pr)
  74. assert y.param[1]=='23'
  75. y = parseSOAPRPC(x, rules=pr2)
  76. assert y.param[1]==23
  77. x = '''<SOAP-ENV:Envelope
  78. SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  79. xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  80. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  81. xmlns:xsd="http://www.w3.org/1999/XMLSchema"
  82. xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
  83. <SOAP-ENV:Body>
  84. <Bounds>
  85. <param>
  86. <item xsi:type="xsd:int">12</item>
  87. <item xsi:type="xsd:string">23</item>
  88. <item xsi:type="xsd:float">0</item>
  89. <item xsi:type="xsd:int">-31</item>
  90. </param>
  91. <param1 xsi:null="1"></param1>
  92. </Bounds>
  93. </SOAP-ENV:Body>
  94. </SOAP-ENV:Envelope>
  95. '''
  96. pr = {'Bounds':
  97. {'param': 'arrayType=ur-type[]'
  98. }
  99. }
  100. y = parseSOAPRPC(x, rules=pr)
  101. assert y.param[0]==12
  102. assert y.param[1]=='23'
  103. assert y.param[2]==float(0)
  104. assert y.param[3]==-31
  105. # Try the reverse, not implemented yet.
  106. def testBuildObject(self):
  107. class Book(structType):
  108. def __init__(self):
  109. self.title = "Title of a book"
  110. class Person(structType):
  111. def __init__(self):
  112. self.age = "49"
  113. self.height = "5.5"
  114. class Library(structType):
  115. def __init__(self):
  116. self._name = "Result"
  117. self.Book = Book()
  118. self.Person = Person()
  119. obj = Library()
  120. x = buildSOAP( kw={'Library':obj} )
  121. print(x)
  122. if __name__ == '__main__':
  123. unittest.main()