Package tlib :: Package base :: Module SoapRequestor |
[hide private]
[frames] | no frames]

# Source Code for Module tlib.base.SoapRequestor

      1  from suds.client import Client
      2  import urllib2
      3
      4
      5 -class SoapRequestor(object):
      6      """
      7      Helper class to contruct and send SOAP requests
      8      """
      9
     10      client = None       #: client object for making calls and receiving responses
     11      api_wsdl = ""        #: WSDL file url / location to define calls
     12      logger = None       #: logger to send loggin information to.  Logger comes from pytest test definitions
     13      my_doctor = None    #: suds Doctor to fix any issues with the wsdl definition
     14
     15 -    def __init__(self, logger, wsdl, the_doctor=None):
     16          """
     17          Constructor for class
     18
     19          Args :
     20          logger : (logger) instance of a logging object configured in testing project
     21          wsdl : (str) URL to the location of the wsdl file
     22          doctor : (ImportDoctor) instance of the suds.xsd.doctor.ImportDoctor class for fixing broken schemas
     23
     24          """
     25
     26          self.logger = logger
     27          self.api_wsdl = wsdl
     28          self.my_doctor = the_doctor
     29          self.create_client();
     30
     31
     32 -    def create_client(self):
     33
     34          try:
     35
     36              self.client = Client(self.api_wsdl, doctor=self.my_doctor)
     37          except urllib2.URLError, e:
     38              print str(e)
     39
     40 -    def get_methods(self):
     41          """
     42          Fetches a list of method objects from the wsdl and returns them in a list
     43
     44          Returns: (list) of suds Method objects containing all information on calling method and handling the response.
     45
     46          """
     47          methods = self.client.wsdl.services[0].ports[0].methods.values()
     48
     49          return methods
     50
     51
     52  # # #create logger
     53  # logger = logging.getLogger('test')
     54  # logger.setLevel(logging.DEBUG)
     55
     56  # # create console handler and set level to debug
     57  # ch = logging.StreamHandler()
     58  # ch.setLevel(logging.DEBUG)
     59
     60  # # create formatter
     61  # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
     62
     63  # # add formatter to ch
     64  # ch.setFormatter(formatter)
     65
     66  # #add ch to logger
     67  # logger.addHandler(ch)
     68  # logging.basicConfig(level=logging.INFO)
     69  # logging.getLogger('suds.client').setLevel(logging.DEBUG)
     70  # logging.getLogger('suds.transport').setLevel(logging.DEBUG)
     71  # logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
     72  # logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
     73
     74  #wsdl = "http://mtljiraqcprod01.ad.ypg.com/SpiraTeam/Services/v4_0/ImportExport.svc?wsdl"
     75  # wsdl = "http://localhost/GetAccountsWithMerchants.WSDL"
     76  # my_soap = SoapRequestor(logger,wsdl)
     77
     78
     79  # #resp = my_soap.client.set_options(service='YPG_spcGet_spcAccounts_spcWith_spcMerchants',port='GetAccounts')
     80  # #print my_soap.client
     81
     82  # methods = my_soap.getMethods()
     83  # print methods
     84
     85  # for method in my_soap.client.wsdl.services[0].ports[0].methods.values():
     86  #     print '%s(%s)' % (method.name, ', '.join('%s: %s' % (part.type, part.name) for part in method.soap.input.body.parts))
     87
     88
     89  #print  methods[0]
     90  #services = my_soap.client.service
     91  #myAccount = my_soap.client.factory.create(u'xsdLocal0:Account')
     92  #myAccount.AccountNum="3333333"
     93  #print myAccount
     94
     95
     96  #print my_soap.client.wsdl.services[0].ports[0].methods.values()[0].soap.input.body.parts
     97  #print services.GetAccounts("Y","","","","4164662766","")
     98  # try :
     99
    100  #       resp = my_soap.client.service.GetAccounts("Y","","","","4164662766","")
    101
    102  # except suds.WebFault, e:
    103  #       print str(e)
    104
    105  # print my_soap.client.last_sent()
    106  #print resp
    107