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

contrib/opal/ZSI/test/wsdl2py/test_BasicComm.py

00001 #!/usr/bin/env python
00002 
00003 import os, sys, unittest
00004 from ServiceTest import main, ServiceTestCase, ServiceTestSuite
00005 from ZSI import FaultException, Fault
00006 from ConfigParser import ConfigParser, NoSectionError, NoOptionError
00007 """
00008 Unittest 
00009 
00010 WSDL:  BasicComm.wsdl
00011 """
00012 CONFIG_FILE = 'config.txt'
00013 CONFIG_PARSER = ConfigParser()
00014 SECTION_DISPATCH = 'dispatch'
00015 
00016 CONFIG_PARSER.read(CONFIG_FILE)
00017 
00018 # General targets
00019 def dispatch():
00020     """Run all dispatch tests"""
00021     suite = ServiceTestSuite()
00022     suite.addTest(unittest.makeSuite(BasicCommTestCase, 'test_dispatch'))
00023     return suite
00024 
00025 def local():
00026     """Run all local tests"""
00027     suite = ServiceTestSuite()
00028     suite.addTest(unittest.makeSuite(BasicCommTestCase, 'test_local'))
00029     return suite
00030 
00031 def net():
00032     """Run all network tests"""
00033     suite = ServiceTestSuite()
00034     suite.addTest(unittest.makeSuite(BasicCommTestCase, 'test_net'))
00035     return suite
00036     
00037 def all():
00038     """Run all tests"""
00039     suite = ServiceTestSuite()
00040     suite.addTest(unittest.makeSuite(BasicCommTestCase, 'test_'))
00041     return suite
00042 
00043 
00044 class BasicCommTestCase(ServiceTestCase):
00045     name = "test_BasicComm"
00046     client_file_name = "BasicServer_client.py"
00047     types_file_name  = "BasicServer_types.py"
00048     server_file_name = "BasicServer_server.py"
00049 
00050     def __init__(self, methodName):
00051         ServiceTestCase.__init__(self, methodName)
00052         self.wsdl2py_args.append('-b')
00053 
00054     def test_local_Basic(self):
00055         msg = self.client_module.BasicRequest()
00056         rsp = self.client_module.BasicResponse()
00057 
00058     def test_dispatch_Basic(self):
00059         loc = self.client_module.BasicServerLocator()
00060         port = loc.getBasicServer(**self.getPortKWArgs())
00061         
00062         msg = self.client_module.BasicRequest()
00063         msg._BasicIn = 'bla bla bla'
00064         rsp = port.Basic(msg)
00065         self.failUnless(rsp._BasicResult == msg._BasicIn, "Bad Echo")
00066 
00067         # test whether we get an HTTP response on a message with
00068         # no soap response.
00069         import httplib
00070         msg = u"""
00071             <SOAP-ENV:Envelope 
00072                xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
00073                xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
00074                xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" 
00075                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
00076                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
00077                  <SOAP-ENV:Header></SOAP-ENV:Header>
00078                  <SOAP-ENV:Body xmlns:ns1="urn:ZSI:examples">
00079                    <ns1:BasicOneWay>
00080                      <ns1:BasicIn>bla bla bla</ns1:BasicIn>
00081                    </ns1:BasicOneWay>
00082                  </SOAP-ENV:Body>
00083             </SOAP-ENV:Envelope>""".encode('utf-8')
00084         headers = {"Content-type": 'text/xml; charset="utf-8"', 'Content-Length': str(len(msg))}
00085 
00086         host = CONFIG_PARSER.get(SECTION_DISPATCH, 'host')
00087         port = CONFIG_PARSER.get(SECTION_DISPATCH, 'port')
00088         path = CONFIG_PARSER.get(SECTION_DISPATCH, 'path')
00089 
00090         conn = httplib.HTTPConnection("%s:%s" % (host, port))
00091         conn.request('POST', '/' + path, msg, headers)
00092         try:
00093             response = conn.getresponse()
00094         except httplib.BadStatusLine:
00095             conn.close()
00096             self.fail('No HTTP Response')
00097 
00098         conn.close()
00099         self.failUnless(response.status == 200, 'Wrong HTTP Result')
00100 
00101     def test_dispatch_BasicOneWay(self):
00102         loc = self.client_module.BasicServerLocator()
00103         port = loc.getBasicServer(**self.getPortKWArgs())
00104         
00105         msg = self.client_module.BasicOneWayRequest()
00106         msg.BasicIn = 'bla bla bla'
00107         rsp = port.BasicOneWay(msg)
00108         self.failUnless(rsp == None, "Bad One-Way")
00109 
00110     def test_dispatch_BasicOneWay_fault(self):
00111         """server will send back a soap:fault
00112         """
00113         loc = self.client_module.BasicServerLocator()
00114         port = loc.getBasicServer(**self.getPortKWArgs())
00115         
00116         msg = self.client_module.BasicOneWayRequest()
00117         msg.BasicIn = 'fault'
00118         self.failUnlessRaises(FaultException, port.BasicOneWay, msg)
00119 
00120 
00121 if __name__ == "__main__" :
00122     main()
00123 

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