File: TCtest.py

package info (click to toggle)
python-soappy 0.9.7-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 500 kB
  • ctags: 1,020
  • sloc: python: 7,572; makefile: 43; sh: 16
file content (115 lines) | stat: -rwxr-xr-x 2,969 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python

from SOAP import *
import sys

x = '''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SomeMethod>
<Result>
<Book>
   <title>My Life and Work</title>
</Book>
<Person>
   <name>Henry Ford</name>
   <age> 49 </age>
   <height> 5.5 </height>
</Person>
</Result>
</SomeMethod>
</soap:Body>
</soap:Envelope>
'''

def negfloat(x):
    return float(x) * -1.0
# parse rules
pr = {'Result':
      {'Book':   {'title':"string"},
       'Person': {'age':"int",
                  'height':negfloat}
       }
      }
y = parseSOAPRPC(x, parse_rules=pr)
assert y.Result.Person.age == 49
assert y.Result.Person.height == -5.5


x = '''
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
   <SOAP-ENV:Body>
   <Bounds>
   <param>
   <item>12</item>
   <item>23</item>
   <item>0</item>
   <item>-31</item>
   </param>
   <param1 xsi:null="1"></param1>
   </Bounds>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'''
# parse rules
pr = {'Bounds':
      {'param': 'arrayType=string[]'
       }
      }

pr2 = {'Bounds':
      {'param': 'arrayType=int[4]'
       }
      }

y = parseSOAPRPC(x, parse_rules=pr)
assert y.param[1]=='23'

y = parseSOAPRPC(x, parse_rules=pr2)
assert y.param[1]==23

x = '''
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
   <SOAP-ENV:Body>
   <Bounds>
   <param>
   <item xsi:type="xsd:int">12</item>
   <item xsi:type="xsd:string">23</item>
   <item xsi:type="xsd:float">0</item>
   <item xsi:type="xsd:int">-31</item>
   </param>
   <param1 xsi:null="1"></param1>
   </Bounds>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'''

pr = {'Bounds':
      {'param': 'arrayType=ur-type[]'
       }
      }
y = parseSOAPRPC(x, parse_rules=pr)
assert y.param[0]==12
assert y.param[1]=='23'
assert y.param[2]==float(0)
assert y.param[3]==-31



# Try the reverse, not implemented yet.

class Book(structType):
    def __init__(self):
        self.title = "Title of a book"
class Person(structType):
    def __init__(self):
        self.age = "49"
        self.height = "5.5"
class Result(structType):
    def __init__(self):
        self._name = "Result"
        self.Book = Book()
        self.Person = Person()

x = buildSOAP(Result())
#sys.exit(0)