• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/opal/ZSI/test/test_t2.py

00001 #!/usr/bin/env python
00002 import unittest, sys
00003 from ZSI import *
00004 
00005 
00006 class t2TestCase(unittest.TestCase):
00007     "Test case wrapper for old ZSI t2 test case"
00008 
00009     def checkt2(self):
00010         try: 
00011             ps = ParsedSoap(IN)
00012         except ParseException, e:
00013              print >>OUT, FaultFromZSIException(e).AsSOAP()
00014              self.fail()
00015         except Exception, e:
00016             # Faulted while processing; assume it's in the
00017             # header.
00018             print >>OUT, FaultFromException(e, 1).AsSOAP()
00019             self.fail()
00020         # We are not prepared to handle any actors or mustUnderstand elements.  
00021         # Arbitrary fault back with the first one found.  
00022         a = ps.WhatActorsArePresent() 
00023         if len(a): 
00024             print >>OUT, FaultFromActor(a[0]).AsSOAP() 
00025             self.fail()
00026         mu = ps.WhatMustIUnderstand() 
00027         if len(mu): 
00028             uri, localname = mu[0] 
00029             print >>OUT, FaultFromNotUnderstood(uri, localname).AsSOAP() 
00030             self.fail() 
00031            
00032                                             
00033         try: 
00034             player = ps.Parse(Player) 
00035         except EvaluateException, e: 
00036             print >>OUT, FaultFromZSIException(e).AsSOAP() 
00037             self.fail() 
00038             
00039         try: 
00040             import operator 
00041             total = reduce(operator.add, player.Scores, 0)
00042             result = Average(foo(total, len(player.Scores)))
00043             sw = SoapWriter().serialize(result) 
00044             print >>OUT, str(sw)
00045         except Exception, e: 
00046             print >>OUT, FaultFromException(e, 0, sys.exc_info()[2]).AsSOAP() 
00047             self.fail()
00048 
00049 
00050 def makeTestSuite():
00051     suite = unittest.TestSuite()
00052     suite.addTest(unittest.makeSuite(t2TestCase, "check"))
00053     return suite
00054 
00055 
00056 class Player: 
00057     '''Input class.''' 
00058     def __init__(self, name=None): 
00059         pass 
00060 Player.typecode = TC.Struct(Player, [ TC.String('Name', optional=1), 
00061                                     TC.Array('xsd:integer', TC.Integer(), 
00062                                     'Scores'), ], 'GetAverage') 
00063 class Average: 
00064     '''Output class.''' 
00065     def __init__(self, average): 
00066         self.average = average 
00067 Average.typecode = TC.Struct(Average, [ TC.Integer('average'), 
00068                                     ], 'GetAverageResponse', inline=1) 
00069 
00070 def bar(total, len): 
00071     return total / len 
00072 
00073 def foo(total, len): 
00074     return bar(total, len) 
00075 
00076 OUT = sys.stdout
00077 IN='''<SOAP-ENV:Envelope
00078  xmlns="http://www.example.com/schemas/TEST"
00079  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
00080  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
00081  xmlns:ZSI="http://www.zolera.com/schemas/ZSI/">
00082  <SOAP-ENV:Header>
00083    <trans SOAP-ENV:mustUnderstand="0"/>
00084  </SOAP-ENV:Header>
00085  <SOAP-ENV:Body>
00086    <GetAverage>
00087      <Scores SOAP-ENC:arrayType="xsd:integer">
00088        <i>84</i>
00089        <xxi>101</xxi>
00090        <foi>200</foi> 
00091        <izzz>4</izzz> 
00092      </Scores> 
00093      <Name>John Doe</Name> 
00094    </GetAverage>
00095  </SOAP-ENV:Body> 
00096 </SOAP-ENV:Envelope>'''
00097 
00098 def main():
00099     unittest.main(defaultTest="makeTestSuite")
00100 
00101 
00102 if __name__ == "__main__" : main()
00103 
00104 

Generated on Wed Oct 20 2010 11:12:16 for APBS by  doxygen 1.7.2