def getRunTestTokenId(projectname="", starTime="sss"): dbManager = getDbManger() starttime = getNowTime() tokenId = uuid.uuid4() sqlstr = "insert into test_run_process(token,starttime,status,projectname) value('%s','%s',1,'%s')" % ( tokenId, starttime, projectname) dbManager.insertData(sql=sqlstr, dbName="ltjtest") return tokenId, starttime
def queryTestResultByPlanIdOrCaseId(planId, caseId): sign = None querySql = """select result_sign from test_case_record r where r.plan_id = %s and r.testcaseid = "%s";""" % ( planId, caseId) result = getDbManger().queryAll(sql=querySql, dbName="ltjtest") if result is not None: sign = result[0][0] return sign
def queryTestPlanByInterfaceName(interfaceName="", planId=22, db=None): dbManager = getDbManger() keyls = [ "interfacename", "testcaseid", "testpoint", "result_sign", "errordes" ] querySql = """select interfacename, testcaseid, testpoint, result_sign, errordes from test_case_record r where r.plan_id = %s and r.interfacename = '%s';""" % (planId, interfaceName) dataList = dbManager.queryAll(sql=querySql, dbName="ltjtest") retList = [dict(zip(keyls, data)) for data in dataList] return retList
def queryTestPlanList(projectName=""): dbManager = getDbManger() keyls = ["id", "plantime", "projectname", "description"] querySql = """select id, plantime, projectname, description from test_plan p where projectname = "%s" ;""" % projectName dataList = dbManager.queryAll(sql=querySql, dbName="ltjtest") retList = [dict(zip(keyls, data)) for data in dataList] retDict = {} retDict["code"] = "000000" retDict["listplan"] = retList return retDict
def queryStateByTokenPro(projectName="", token=""): dbManager = getDbManger() keyls = [ "id", "starttime", "status", "endtime", "projectname", "hourtime", "mintime", "sectime" ] querySql = """select id, starttime, status, endtime, projectname ,HOUR(timediff(endtime , starttime)) hourtime ,minute(timediff(endtime , starttime)) mintime,SECOND(timediff(endtime , starttime)) sectime from test_run_process p where p.projectname = "%s" and p.token = "%s";""" % (projectName, token) dataList = dbManager.queryAll(sql=querySql, dbName="ltjtest") if dataList is not None and len(dataList) > 0: return dict(zip(keyls, dataList[0]))
def queryTestPlanRecord(planId=11): dbManager = getDbManger() keyls = ["interfaceName", "success", "fail", "error", "total"] querySql = """select r.interfacename 'interfaceName', CONVERT(sum(case r.result_sign when '0' then 1 else 0 end) ,SIGNED ) 'success', CONVERT(sum(case r.result_sign when '1' then 1 else 0 end),SIGNED ) 'fail', CONVERT(sum(case r.result_sign when '2' then 1 else 0 end),SIGNED ) 'error', CONVERT(sum(1),SIGNED ) 'total' from test_case_record r where r.plan_id = %s group by r.interfacename;""" % planId dataList = dbManager.queryAll(sql=querySql, dbName="ltjtest") if dataList is None: dataList = [] retList = [dict(zip(keyls, data)) for data in dataList] return retList
def insertInterfaceTable(): dbManger = getDbManger() for urlsign in httpData: method = httpData[urlsign][0] url = httpData[urlsign][2] module = httpData[urlsign][3] title = httpData[urlsign][4] for httpformat in httpData[urlsign][1]: reqjsonpath = httpData[urlsign][1][httpformat][1].replace( os.sep, os.sep + os.sep) rspjsonpath = httpData[urlsign][1][httpformat][3].replace( os.sep, os.sep + os.sep) sqlStr = "insert interface_mgr(aliasName,interfaceNameAddr,reqDataPath,rspDataPath, \ projectname,reqtype,module,mark) value('%s','%s','%s','%s','%s','%s','%s','%s')" % (urlsign,url, \ reqjsonpath,rspjsonpath,'steam亲子教育',method,module,title) print(sqlStr) dbManger.insertData(sql_insert=sqlStr)
def queryAllInterfaceByProjectName(projectName=None): dbManager = getDbManger() keyls = [ "aliasName", "interfaceAddr", "reqtype", "module", "mark", "reqpath", "rsppath", "sign" ] querySql = """select inf.aliasName,inf.interfaceNameAddr,inf.reqtype,CONCAT(mt.mtype,'-',mt.module ) as 'module',inf.mark,inf.reqDataPath,inf.rspDataPath ,0 from interface_mgr inf,module_type mt where inf.projectname = "%s" and inf.module = mt.module order by mt.sortsign;""" % projectName dataList = dbManager.queryAll(sql=querySql, dbName="ltjtest") if dataList is None: dataList = [] retList = [dict(zip(keyls, data)) for data in dataList] for data in retList: if data["aliasName"] in interfaceAliasList: data["sign"] = 1 #sorted(retList,key = lambda a: a["sign"] ) retList.sort(key=lambda a: a["sign"], reverse=True) retdata = {"code": "000000", "infsList": retList} return retdata