""" $Id: SOAPUnit.py,v 1.5 2001/01/12 16:52:58 kmacleod Exp $ """ import unittest from types import * from Orchard.Node import Node from Orchard.SOAP import * import Orchard.XML xmlns_ns = "http://www.w3.org/2000/xmlns/" soap_enc_ns = "http://schemas.xmlsoap.org/soap/encoding/" soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/" xsi_ns = "http://www.w3.org/1999/XMLSchema-instance" body = Node() body[(soap_env_ns, 'Body')] = { 'integer' : 1, 'float' : 2.0, 'string' : 'A String', 'list' : ['A', 'List'], 'record' : { 'A' : 'Record' }, 'none' : None, } envelope = Node() envelope[(xmlns_ns, 'SOAP-ENC')] = soap_enc_ns envelope[(xmlns_ns, 'SOAP-ENV')] = soap_env_ns envelope[(xmlns_ns, 'xsi')] = xsi_ns envelope[(soap_env_ns, 'Envelope')] = body simple_types = { 'root' : { 'integer' : 1, 'float' : 2.0, 'string' : 'A String', 'list' : ['A', 'List'], 'record' : { 'A' : 'Record' }, 'none' : None, } } class SOAPUnitTestCase(unittest.TestCase): def checkPickle(self): xml_string = dumps(envelope) xml_tree = Orchard.XML.load(xml_string) assert xml_tree.root.name == 'SOAP-ENV:Envelope' assert xml_tree.root.contents[0].name == 'SOAP-ENV:Body' assert (xml_tree.root.attributes[(xmlns_ns, 'SOAP-ENC')].value == soap_enc_ns) assert (xml_tree.root.attributes[(xmlns_ns, 'SOAP-ENV')].value == soap_env_ns) assert (xml_tree.root.attributes[(xmlns_ns, 'xsi')].value == xsi_ns) dict = Node() for node in xml_tree.root.contents[0].contents: dict[str(node.name)] = node assert dict.integer.contents[0].data == '1' assert dict.float.contents[0].data == '2.0' assert dict.string.contents[0].data == 'A String' assert len(dict.list.contents) == 2 assert (dict.list.attributes[(soap_enc_ns, 'arrayType')].value == 'item[]') assert dict.record.contents[0].name == 'A' assert dict.record.contents[0].contents[0].data == 'Record' assert dict.none.attributes[(xsi_ns, 'null')].value == '1' def checkUnpickler(self): xml_string = dumps(envelope) object = loads(xml_string) object = object[(soap_env_ns, 'Envelope')][(soap_env_ns, 'Body')] assert object.integer == 1 assert object.float == 2.0 assert object.string == 'A String' assert len(object.list) == 2 assert object.list[0] == 'A' assert object.list[1] == 'List' assert object.record['A'] == 'Record' assert object.none is None def checkUnknownPickleType(self): try: dumps(lambda: None) raise AssertionError, "expected unknown type PicklingError" except PicklingError: pass def checkEncodeCall(self): namespace = "urn:n3-user-validation" context = Context(namespace=namespace) xml_string = context.encode_call('foo', [ { 'zip' : 'zap' } ]) object = loads(xml_string) object = object[(soap_env_ns, 'Envelope')][(soap_env_ns, 'Body')][(namespace, 'foo')]['arg1'] assert object.zip == 'zap' def checkSimplePickle(self): xml_string = dumps(simple_types) xml_tree = Orchard.XML.load(xml_string) assert xml_tree.root.name == 'root' assert (xml_tree.root.attributes[(xmlns_ns, 'SOAP-ENC')].value == soap_enc_ns) assert (xml_tree.root.attributes[(xmlns_ns, 'SOAP-ENV')].value == soap_env_ns) assert (xml_tree.root.attributes[(xmlns_ns, 'xsi')].value == xsi_ns) assert (xml_tree.root.attributes[(soap_env_ns, 'encodingStyle')].value == "http://schemas.xmlsoap.org/soap/encoding/") dict = Node() for node in xml_tree.root.contents: dict[str(node.name)] = node assert dict.integer.contents[0].data == '1' assert dict.float.contents[0].data == '2.0' assert dict.string.contents[0].data == 'A String' assert len(dict.list.contents) == 2 assert (dict.list.attributes[(soap_enc_ns, 'arrayType')].value == 'item[]') assert dict.record.contents[0].name == 'A' assert dict.record.contents[0].contents[0].data == 'Record' assert dict.none.attributes[(xsi_ns, 'null')].value == '1' def suite(): return unittest.makeSuite(SOAPUnitTestCase,'check') if __name__ == "__main__": unittest.TextTestRunner().run(suite())