#!/usr/bin/env python
import sys, unittest
sys.path.insert(1, "..")
from SOAPpy import *
Config.debug=1
class ClientTestCase(unittest.TestCase):
def testParseRules(self):
x = """
My Life and Work
Henry Ford
49
5.5
"""
def negfloat(x):
return float(x) * -1.0
# parse rules
pr = {'SomeMethod':
{'Result':
{
'Book': {'title':'string'},
'Person': {'age':'int',
'height':negfloat}
}
}
}
y = parseSOAPRPC(x, rules=pr)
assert y.Result.Person.age == 49
assert y.Result.Person.height == -5.5
x = '''
- 12
- 23
- 0
- -31
'''
# parse rules
pr = {'Bounds':
{'param': 'arrayType=string[]',
}
}
pr2 = {'Bounds':
{'param': 'arrayType=int[4]',
}
}
y = parseSOAPRPC(x, rules=pr)
assert y.param[1]=='23'
y = parseSOAPRPC(x, rules=pr2)
assert y.param[1]==23
x = '''
- 12
- 23
- 0
- -31
'''
pr = {'Bounds':
{'param': 'arrayType=ur-type[]'
}
}
y = parseSOAPRPC(x, 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.
def testBuildObject(self):
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 Library(structType):
def __init__(self):
self._name = "Result"
self.Book = Book()
self.Person = Person()
obj = Library()
x = buildSOAP( kw={'Library':obj} )
print(x)
if __name__ == '__main__':
unittest.main()