def runOneTestCase(): """ 执行一个指定的用例 :return: """ planId = int(request.args.get("planId")) projectName = request.args.get("projectname") caseId = request.args.get("caseId") interfaceName = request.args.get("interfaceName") print("planId=%s,projectName=%s,caseId=%s,interfaceName=%s" % (planId, projectName, caseId, interfaceName)) token = queryTokenByPlanId(planId=planId, projectName=projectName) global writeDir logDir = genDir() writeDir = writeLog(wtrDir=logDir) testcases = initAllTestCase(casepath) testclass = initAllTestClass() testSuite = genTestCaseByInterfaceOrCaseIds(allTestClass=testclass, allCase=testcases, interfaceName=interfaceName, caseIds=[caseId]) runOneTestcase(suites=testSuite, planId=planId, token=token, title=projectName, description="%s-用例测试情况" % projectName) return jsonify({ "code": "000000", "token": token })
def start_steam_tasks(): """ 执行所有用例 """ projectName = request.args.get("projectname") retdata = getRunTestTokenId(projectname=projectName) global writeDir logDir = genDir(str(retdata[2])) writeDir = writeLog(wtrDir=logDir) testcases = initAllTestCase(casepath) testclass = initAllTestClass() testSuite = genAllTestCase(allCase=testcases, allTestClass=testclass) t = threading.Thread(target=runAllTestCase, kwargs={ "suites": testSuite, "title": projectName, "description": "%s-用例测试情况" % projectName, "token": retdata[0] } ) t.start() return jsonify({ 'sign': "000000", "token": retdata[0], "starttime": retdata[1] })
def runTestCase(suites=None, title="", description=""): global writeDir logDir = genDir() writeDir = writeLog(wtrDir=logDir) runner = HTMLTestRunner.HTMLTestRunner(stream=None, title=title, description=description) unitresult = runner.runSteam(suites) return unitresult
def runOneTestClass(interfaceName,ids=None): from opg.util.timeTool import getTwoFmtTime starttime, logtime = getTwoFmtTime() global writeDir logDir = genDir(str(logtime)) writeDir = writeLog(wtrDir=logDir) testSuite = genTestCaseByInterfaceOrCaseIds( allTestClass = initData.allTestClass , allCase = initData.allTestCase , interfaceName = interfaceName, caseIds = ids ) runOneCls(testSuite,casepath)
def runTestOneCls(suites, basepath): global writeDir logDir = genDir() writeDir = writeLog(wtrDir=logDir) HtmlFile = basepath + os.sep + "testresult" + os.sep + "HTMLtemplate.html" fp = open(HtmlFile, "wb") runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"小红巢测试报告", description=u"用例测试情况") unitresult = runner.run(suites) return unitresult
def __init__(self): self.urlDict = { "weixin": { "codeurl": "/passport/verifyCode", "loginurl": "/member/login/memberLogin" }, "admin": { "codeurl": "/operation-manage/permission/admin/SmsCodeSend", "loginurl": "/operation-manage/permission/admin/login" }, "merchants": { "codeurl": "/merchant/passport/verifyCode", "loginurl": "/merchant-service/merchant/login" }, } self.tkdict = defaultdict(dict) if TokenData.sign: logdir = genDir("token") sh = writeLog(logdir, logtag="tokenlog")() selectFh(sh) self.initTokenData() selectFh(sh, sign=False) TokenData.sign = False
def checkTestData(): from opg.util.timeTool import getNowTime, getTwoFmtTime global sh datetime,logtime = getTwoFmtTime() logDir = genDir(logtime) writeDir = writeLog(wtrDir=logDir) sh = writeDir("checkTestData.log") selectFh(sh) testdataFilePath = casepath + os.sep + "testdata" + \ os.sep + "testData.yml" testdata = loadYamlFileData(filePath = testdataFilePath) sign = True for apiListData in testdata["testdata"]: apiInterface = apiListData["apiInterface"] testClass = allTestClass[apiInterface] for data in apiListData["data"]: dataPath = data["dataPath"] casedata = [1,2,3,4,5,data,7,8] tc = testClass( methodName = "compareRetcodeTest" , param = casedata ) checkCode = tc.myservice.findTestdataByStatus() print("checkCode = " + checkCode) if checkCode != "000000": sign = False retcode = sendReqByCode(code = checkCode, fileName = dataPath, inputData = data) if retcode == "211111": print("无需重建") elif retcode == "000000": print("重建数据成功") elif retcode == "200001": print("重建中返回报文数据异常") else: print("重建出错,对应返回码为%s" % retcode) selectFh(sh,False) return sign