コード例 #1
0
 def _execute(self, default, step, control):
     if control['loop']['running'] and 0 == control['loop']['count']:
         control['loop']['steps'].append({'step':step, 'executor':self})
     
     sid = DictUtils.defaultIfNone(step, None, 'sid')    
     if None == sid:
         TestExecutor._LOGGER.error("missing id for step: " + str(step))
         sys.exit(1)
     host = DictUtils.defaultIfNone(step, default, 'host')
     path = DictUtils.defaultIfNone(step, default, 'path')
     method = DictUtils.defaultIfNone(step, default, 'method')
     commonInputData = DictUtils.defaultIfNone(None, default, 'input')
     inputData = DictUtils.defaultIfNone(step, default, 'input')
     
     if None != path:
         if path.startswith('/'):
             url = host + path
         else:
             url = host + '/' + path
     else:
         url = host
     
     url = self.__detemplatizeStr(url, control)
     TestExecutor._LOGGER.debug("url: " + url)
     
     if None == inputData:
         inputData = commonInputData
     elif None != commonInputData:
         inputData.update(commonInputData)
     
     if None != inputData:
         inputData = self.__detemplatize(inputData, control, boolToStr=True)
         # data = DictUtils.recursiveUrlencode(inputData)
     else:
         inputData = dict()
     
     TestExecutor._LOGGER.debug("request inputData: " + str(inputData))
     
     startTime = time.time()
     
     try:
         if 'POST' == method:
             #res = urllib2.urlopen(url, data)
             files = self.__extractFiles(inputData)
             data, headers = DictUtils.encode_multipart(inputData, files)
             if None == files or 0 == len(files):
                 TestExecutor._LOGGER.debug("request data: " + str(data))
             else:
                 TestExecutor._LOGGER.debug("request data: SOME POST DATA with files (won't log)")
             req = urllib2.Request(url, data=data, headers=headers)
             res = urllib2.urlopen(req)
         else:
             data = DictUtils.recursiveUrlencode(inputData)
             TestExecutor._LOGGER.debug("request data: " + data)
             url += "?" + data
             res = urllib2.urlopen(url)
     except IOError, e:
         TestExecutor._LOGGER.debug("caught exception e:" + str(e))
         isSuccess = False
         if hasattr(e, 'code'):
             statusCode = e.code
         else:
             statusCode = 500
         if hasattr(e, 'reason'):
             response = e.reason
         else:
             response = ""