def __init__(self, debugType=Do.TYPE_DEBUG_INTERFACE, dubboInterface=DubboInterface(), dubboCase=DubboTestcase()): super(DubboCaseDebugThread, self).__init__() self.debugType = debugType self.dubboInterface = dubboInterface self.dubboCase = dubboCase
def run(self): if self.debugType == Do.TYPE_DEBUG_INTERFACE: self.dubboInterface = DubboInterface( interfaceDebugId=self.interfaceDebugId) self.dubboInterface.generateByInterfaceDebugIdForRedis() if self.dubboInterface.execStatus != 1: logging.info("没有查到接口调试信息interfaceDebugId[%s]" % self.interfaceDebugId) return self.debugInterface(self.dubboInterface) elif self.debugType == Do.TYPE_DEBUG_CASE: # self.debugCase() self.dubboCase = DubboTestcase() self.dubboCase.generateByCaseDebugIdAndCaseStepDebugIdList( self.caseDebugId, self.caseStepDebugId) if len(self.dubboCase.stepTestcaseList) == 0: logging.info("用例步骤数量为0,不进行用例调试") return self.debugCase(self.dubboCase) else: logging.error("错误的调试类型debugType.")
def generateByTaskExecuteId(self): """ 生成任务通过 任务执行id从tb_task_execute查询任务属性 Returns: 无 """ self.globalDB.initGlobalDBConf() self.taskExecuteId = int(self.taskExecuteId) sqlTasExec = "select * from tb2_dubbo_task_execute where id=%d" % int( self.taskExecuteId) resTaskExec = self.globalDB.execute_sql(sqlTasExec) if resTaskExec: tmpResTaskInfo = resTaskExec[0] self.id = tmpResTaskInfo['id'] # tb_task的主键id self.taskId = tmpResTaskInfo['taskId'] self.traceId = md5("%s-%s" % (self.taskId, get_current_time())) self.title = tmpResTaskInfo['title'] self.taskDesc = tmpResTaskInfo['taskdesc'] self.protocol = tmpResTaskInfo['protocol'] self.businessLineGroup = tmpResTaskInfo['businessLineGroup'] self.modulesGroup = tmpResTaskInfo['modulesGroup'] self.taskLevel = tmpResTaskInfo['taskLevel'] self.status = tmpResTaskInfo['status'] self.version = tmpResTaskInfo['version'] self.interfaceCount = int(tmpResTaskInfo['interfaceCount']) self.taskInterfaces = tmpResTaskInfo[ 'taskInterfaces'] # Done 需要根据列表生成对应的用例任务集合列表taskinterfaceList self.caseCount = int(tmpResTaskInfo['caseCount']) self.taskCases = tmpResTaskInfo[ 'taskTestcases'] # Done 需要根据列表生成对应的用例任务集合列表taskcasesList self.caseLevel = tmpResTaskInfo["caseLevel"] self.httpConfKey = tmpResTaskInfo['httpConfKey'] self.confHttpLayer.key = self.httpConfKey self.confHttpLayer.generate_http_conf_by_key() self.highPriorityVARSStr = tmpResTaskInfo['highPriorityVARS'] self.highPriorityVARSDict = {} # 优先变量 self.isSendEmail = int(tmpResTaskInfo['isSendEmail']) self.isCodeRate = int(tmpResTaskInfo['isCodeRate']) self.isSaveHistory = int(tmpResTaskInfo['isSaveHistory']) self.execComments = tmpResTaskInfo['execComments'] self.retryCount = int(tmpResTaskInfo['retryCount']) #重试次数,默认是0 self.execType = tmpResTaskInfo['execType'] self.execTime = tmpResTaskInfo['execTime'] self.execFinishTime = tmpResTaskInfo['execFinishTime'] self.execBy = tmpResTaskInfo['execBy'] self.execStatus = tmpResTaskInfo['execStatus'] self.execProgressData = tmpResTaskInfo['execProgressData'] self.execPlatform = tmpResTaskInfo['execPlatform'] self.execLevel = int(tmpResTaskInfo['execLevel']) self.testResult = tmpResTaskInfo['testResult'] self.testResultMsg = tmpResTaskInfo['testResultMsg'] self.testReportUrl = tmpResTaskInfo['testReportUrl'] self.state = tmpResTaskInfo['state'] self.addBy = tmpResTaskInfo['addBy'] self.modBy = tmpResTaskInfo['modBy'] self.addTime = tmpResTaskInfo['addTime'] self.modTime = tmpResTaskInfo['modTime'] # 根据version来获取 if self.version == "CurrentVersion": self.taskTestcaseList = [] caseIdList = self.taskCases.split(",") getCaseListSql = "" for tmpCaseId in caseIdList: getCaseListSql += "select * from tb2_dubbo_testcase where state = 1 and caseId='%s' union all " % tmpCaseId getCaseListSql = getCaseListSql[:-11] resCaseListData = self.globalDB.execute_sql(getCaseListSql) caseListForIn = "" for tCid in caseIdList: caseListForIn += "'%s'," % tCid caseListForIn = caseListForIn[:-1] sqlCaseSteps = "select * from tb2_dubbo_testcase_step where state = 1 and caseId in (%s) order by stepNum asc" % caseListForIn resCaseStepData = self.globalDB.execute_sql(sqlCaseSteps) resCaseStepDict = {} for tmpCaseStep in resCaseStepData: if tmpCaseStep['caseId'] not in resCaseStepDict.keys(): resCaseStepDict[tmpCaseStep['caseId']] = [] tmpCaseStep['version'] = self.version resCaseStepDict[tmpCaseStep['caseId']].append(tmpCaseStep) for tmpCaseDict in resCaseListData: if tmpCaseDict['caseId'] == "": continue tmpHttpCase = DubboTestcase() tmpHttpCase.confHttpLayer = self.confHttpLayer tmpHttpCase.version = self.version tmpCaseDict['version'] = self.version tmpHttpCase.generateByCaseDict( tmpCaseDict, resCaseStepDict[tmpCaseDict['caseId']]) self.taskTestcaseList.append(tmpHttpCase) self.taskInterfaceList = [] interfaceIdList = self.taskInterfaces.split(",") getInterfaceListSql = "" for tmpInterfaceId in interfaceIdList: getInterfaceListSql += " SELECT * FROM tb2_dubbo_interface where state = 1 and interfaceId = '%s' union all " % ( tmpInterfaceId) getInterfaceListSql = getInterfaceListSql[:-11] resInterfaceListData = self.globalDB.execute_sql( getInterfaceListSql) for tmpInterfacceDict in resInterfaceListData: if tmpInterfacceDict['interfaceId'] == "": continue tmpInterface = DubboInterface() tmpInterface.confHttpLayer = self.confHttpLayer tmpInterface.version = self.version tmpInterfacceDict['version'] = self.version tmpInterface.generateByInterfaceDict(tmpInterfacceDict) self.taskInterfaceList.append(tmpInterface) else: # 去version表获取 self.taskTestcaseList = [] caseIdList = self.taskCases.split(",") getCaseListSql = "" for tmpCaseId in caseIdList: getCaseListSql += "select * from tb_version_http_testcase where state = 1 and caseId='%s' and versionName='%s' union all " % ( tmpCaseId, self.version) getCaseListSql = getCaseListSql[:-11] resCaseListData = self.globalDB.execute_sql(getCaseListSql) caseListForIn = "" for tCid in caseIdList: caseListForIn += "'%s'," % tCid caseListForIn = caseListForIn[:-1] sqlCaseSteps = "select * from tb_version_http_testcase_step where state = 1 and caseId in (%s) and versionName='%s' order by stepNum asc" % ( caseListForIn, self.version) resCaseStepData = self.globalDB.execute_sql(sqlCaseSteps) resCaseStepDict = {} for tmpCaseStep in resCaseStepData: if tmpCaseStep['caseId'] not in resCaseStepDict.keys(): resCaseStepDict[tmpCaseStep['caseId']] = [] tmpCaseStep['version'] = self.version resCaseStepDict[tmpCaseStep['caseId']].append(tmpCaseStep) for tmpCaseDict in resCaseListData: if tmpCaseDict['caseId'] == "": continue tmpHttpCase = DubboTestcase() tmpHttpCase.confHttpLayer = self.confHttpLayer tmpHttpCase.version = self.version tmpCaseDict['version'] = self.version tmpHttpCase.generateByCaseDict( tmpCaseDict, resCaseStepDict[tmpCaseDict['caseId']]) self.taskTestcaseList.append(tmpHttpCase) self.taskInterfaceList = [] interfaceIdList = self.taskInterfaces.split(",") getInterfaceListSql = "" for tmpInterfaceId in interfaceIdList: getInterfaceListSql += " SELECT * FROM tb_version_http_interface where state = 1 and interfaceId = '%s' and versionName='%s' union all " % ( tmpInterfaceId, self.version) getInterfaceListSql = getInterfaceListSql[:-11] resInterfaceListData = self.globalDB.execute_sql( getInterfaceListSql) for tmpInterfacceDict in resInterfaceListData: if tmpInterfacceDict['interfaceId'] == "": continue tmpInterface = DubboInterface() tmpInterface.confHttpLayer = self.confHttpLayer tmpInterface.version = self.version tmpInterfacceDict['version'] = self.version tmpInterface.generateByInterfaceDict(tmpInterfacceDict) self.taskInterfaceList.append(tmpInterface) self.globalDB.release()
class DubboCaseDebugProgress(multiprocessing.Process): def __init__(self, debugType=Do.TYPE_DEBUG_INTERFACE, interfaceDebugId="", caseDebugId="", caseDebugStepId=""): multiprocessing.Process.__init__(self) # super(DubboCaseDebugThread, self).__init__() self.debugType = debugType self.interfaceDebugId = interfaceDebugId self.caseDebugId = caseDebugId self.caseStepDebugId = caseDebugStepId # if self.debugType == Do.TYPE_DEBUG_INTERFACE: # self.dubboInterface = DubboInterface(interfaceDebugId=interfaceDebugId) # if self.dubboInterface.execStatus != 1: # logging.info("没有查到接口调试信息interfaceDebugId[%s]" % interfaceDebugId) # return # # self.dubboInterface.interfaceDebugId = interfaceDebugId # self.dubboInterface.generateByInterfaceDebugIdForRedis() # elif self.debugType == Do.TYPE_DEBUG_CASE: # self.dubboCase = DubboTestcase() # # self.dubboCase.caseDebugId = caseDebugId # # self.dubboCase.caseStepList = stepTestcaseList # self.dubboCase.generateByCaseDebugIdAndCaseStepDebugIdList(caseDebugId,stepTestcaseList) @catch_exception @take_time def run(self): if self.debugType == Do.TYPE_DEBUG_INTERFACE: self.dubboInterface = DubboInterface( interfaceDebugId=self.interfaceDebugId) self.dubboInterface.generateByInterfaceDebugIdForRedis() if self.dubboInterface.execStatus != 1: logging.info("没有查到接口调试信息interfaceDebugId[%s]" % self.interfaceDebugId) return self.debugInterface(self.dubboInterface) elif self.debugType == Do.TYPE_DEBUG_CASE: # self.debugCase() self.dubboCase = DubboTestcase() self.dubboCase.generateByCaseDebugIdAndCaseStepDebugIdList( self.caseDebugId, self.caseStepDebugId) if len(self.dubboCase.stepTestcaseList) == 0: logging.info("用例步骤数量为0,不进行用例调试") return self.debugCase(self.dubboCase) else: logging.error("错误的调试类型debugType.") @catch_exception @take_time def debugInterface(self, dubboInterface): logging.debug("开始进行接口调试!") # dubboInterface.executeInterface() # dubboInterface.updateByInterfaceDebugId() DubboService().execute_debug_interface(interface=self.dubboInterface) logging.debug('接口调试Done!') @catch_exception @take_time def debugCase(self, dubboTestCase): logging.debug("开始进行用例调试!") # self.dubboCase.execute() # self.dubboCase.updateByCaseDebugId() DubboService().execute_debug_testcases(testcase=self.dubboCase) logging.debug('CASE debug Done!')
def execute_debug_interface(self, interface=DubboInterface()): #data process DBINFO interface.executeInterface() interface.updateByInterfaceDebugId() return interface