class CaseDebugProcess(multiprocessing.Process): def __init__(self, debugType=Do.TYPE_DEBUG_INTERFACE, interfaceDebugId=0, testCaseDebugId=0, testCaseStepDebugId=0): # super(CaseDebugProcess, self).__init__() multiprocessing.Process.__init__(self) self.debugType = debugType self.interfaceDebugId = interfaceDebugId self.testCaseDebugId = testCaseDebugId self.testCaseStepDebugId = testCaseStepDebugId # self.httpInterface = httpInterface # self.httpCase = httpCase @catch_exception @take_time def run(self): if self.debugType == Do.TYPE_DEBUG_INTERFACE: self.httpInterface = HttpInterface( interfaceDebugId=self.interfaceDebugId) self.httpInterface.generateByInterfaceDebugId() if self.httpInterface.execStatus != 1: logging.info("没有查到接口调试信息interfaceDebugId[%s]" % self.interfaceDebugId) return self.debugInterface() elif self.debugType == Do.TYPE_DEBUG_CASE: self.httpCase = HttpTestcase() self.httpCase.generateByCaseDebugIdAndCaseStepDebugIdList( self.testCaseDebugId, self.testCaseStepDebugId) if len(self.httpCase.stepTestcaseList) == 0: logging.info("用例步骤数量为0,不进行用例调试") return self.debugCase() else: logging.error("错误的调试类型debugType.") @catch_exception @take_time def debugInterface(self): logging.debug("开始进行接口调试!") HttpService().execute_debug_interface(self.httpInterface) logging.debug('接口调试Done!') @catch_exception @take_time def debugCase(self): logging.debug("开始进行用例调试!") HttpService().execute_debug_testcases(self.httpCase) logging.debug('CASE debug Done!')
def __init__(self, debugType=Do.TYPE_DEBUG_INTERFACE, httpInterface=HttpInterface(), httpCase=HttpTestcase()): super(CaseDebugThread, self).__init__() self.debugType = debugType self.httpInterface = httpInterface self.httpCase = httpCase
def run(self): if self.debugType == Do.TYPE_DEBUG_INTERFACE: self.httpInterface = HttpInterface( interfaceDebugId=self.interfaceDebugId) self.httpInterface.generateByInterfaceDebugId() if self.httpInterface.execStatus != 1: logging.info("没有查到接口调试信息interfaceDebugId[%s]" % self.interfaceDebugId) return self.debugInterface() elif self.debugType == Do.TYPE_DEBUG_CASE: self.httpCase = HttpTestcase() self.httpCase.generateByCaseDebugIdAndCaseStepDebugIdList( self.testCaseDebugId, self.testCaseStepDebugId) if len(self.httpCase.stepTestcaseList) == 0: logging.info("用例步骤数量为0,不进行用例调试") return self.debugCase() else: logging.error("错误的调试类型debugType.")
def generateByTaskExecuteId(self): """ 生成任务通过 任务执行id从tb_task_execute查询任务属性 Returns: 无 """ self.globalDB.initGlobalDBConf() self.taskExecuteId = int(self.taskExecuteId) sqlTasExec = "select * from tb_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.taskSuiteExecuteId = tmpResTaskInfo["taskSuiteExecuteId"] self.title = tmpResTaskInfo['title'] self.taskDesc = tmpResTaskInfo['taskdesc'] self.protocol = tmpResTaskInfo['protocol'] self.businessLineGroup = tmpResTaskInfo['businessLineGroup'] self.modulesGroup = tmpResTaskInfo['modulesGroup'] self.sourceGroup = tmpResTaskInfo['sourceGroup'] 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 #TODO 此处应当生成优先变量 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.highPriorityVARSStr = "[CONF=common]areal = 1;$IMPORT[testkey];myGReal = $GVAR[WJL_TEST_GVAR_KEY];[ENDCONF]" # 通过Str生成dict 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.performanceResult = tmpResTaskInfo['performanceResult'] 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 tb_http_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 tb_http_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['stepSwitch'] == TestCaseStepSwitch.NOT_SWITCH: continue 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 = HttpTestcase() 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_http_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 = HttpInterface() 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 = HttpTestcase() 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 = HttpInterface() tmpInterface.confHttpLayer = self.confHttpLayer tmpInterface.version = self.version tmpInterfacceDict['version'] = self.version tmpInterface.generateByInterfaceDict(tmpInterfacceDict) self.taskInterfaceList.append(tmpInterface) self.globalDB.release()
def execute_debug_interface(self, interface=HttpInterface()): #data process DBINFO interface.executeInterface() interface.updateByInterfaceDebugId() return interface