示例#1
0
def againRunTask(request):
    #历史版本再次执行取任务错误。
    id = request.GET.get("id")
    res = HTTP_task_executeService.againRunTask(
        id, request.session.get("loginName"), request.session.get("userName"))
    if res == False:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, '任务已被删除').toJson())

    result = dbModelToDict(res)
    tcpin = '{"do":3,"TaskExecuteId":%s,"TaskExecuteEnv":"%s","TaskId":"%s","protocol":"HTTP"}' % (
        result["id"], result["httpConfKey_id"], result["taskId"])
    RedisCache().set_data("%s_taskExecute_%s" % ("HTTP", result["id"]),
                          "0:0:0:0:0")
    RedisCache().set_data("%s_taskExecuteStatus_%s" % ("HTTP", result["id"]),
                          "1")
    retApiResult = send_tcp_request(tcpin)
    if retApiResult.code != ApiReturn.CODE_OK:
        HTTP_task_executeService.updateFailExecute(result["id"],
                                                   retApiResult.message)
        RedisCache().del_data("%s_taskExecute_%s" % ("HTTP", result["id"]))
        RedisCache().del_data("%s_taskExecuteStatus_%s" %
                              ("HTTP", result["id"]))
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                      retApiResult.message).toJson())
    return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
示例#2
0
def getInterfeceListData(request):
    #根据任务执行结果
    id = request.GET.get("id")
    taskDataModel = HTTP_task_executeService.findTaskRestltForId(id)
    taskData = dbModelToDict(taskDataModel)
    if taskDataModel.version == "CurrentVersion":
        getInterFaceDataSql = taskData["taskInterfaces"].replace(
            ",",
            "' union all select thi.id,thi.interfaceId,thi.title,thi.casedesc,thi.url,thi.addBy,tu.userName from tb_http_interface thi  LEFT JOIN tb_user tu on thi.addBy = tu .loginName  where interfaceId = '"
        )
        sql = "select thi.id,thi.interfaceId,thi.title,thi.casedesc,thi.url,thi.addBy,tu.userName from tb_http_interface thi  LEFT JOIN tb_user tu on thi.addBy = tu .loginName  where interfaceId = '%s'" % getInterFaceDataSql
    else:
        getInterFaceDataSql = taskData["taskInterfaces"].replace(
            ",",
            "' union all select thi.id,thi.interfaceId,thi.title,thi.casedesc,thi.url,thi.addBy,tu.userName from tb_version_http_interface thi  LEFT JOIN tb_user tu on thi.addBy = tu .loginName  where interfaceId = '"
        )
        sql = "select thi.id,thi.interfaceId,thi.title,thi.casedesc,thi.url,thi.addBy,tu.userName from tb_version_http_interface thi  LEFT JOIN tb_user tu on thi.addBy = tu .loginName  where interfaceId = '%s' and versionName='%s'" % (
            getInterFaceDataSql, taskDataModel.version)

    taskInterfaceListData = executeSqlGetDict(sql)
    response = render(
        request,
        "InterfaceTest/HTTPTask/SubPages/HTTP_Task_Details_Select_interface_list_check_page.html",
        {"pageDatas": taskInterfaceListData})
    return response
示例#3
0
def getTaskRestltDetail(request):
    id = request.GET.get("id")
    taskExecDataModel = HTTP_task_executeService.findTaskRestltForId(id)
    taskExecData = dbModelToDict(taskExecDataModel)
    taskExecData.update(dbModelToDict(taskExecDataModel.httpConfKey))
    taskExecData.update(dbModelToDict(taskExecDataModel.addBy))
    return HttpResponse(
        ApiReturn(ApiReturn.CODE_OK, body=json.dumps(taskExecData)).toJson())
示例#4
0
def stopTaskRun(request):
    id = request.GET.get("id")
    taskSuiteExecuteId = request.GET.get("taskSuiteExecuteId")
    try:
        HTTP_task_executeService.stopTaskRun(id)
        RedisCache().set_data("%s_taskExecuteStatus_%s" % ("HTTP", id), "10")
    except Exception as e:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                      "请验证id正确性%s" % e).toJson())
    tcpin = '{"do":4,"TaskExecuteId":%s,"protocol":"HTTP","TaskSuiteExecuteId":%s}' % (
        id, taskSuiteExecuteId)
    retApiResult = send_tcp_request(tcpin)
    if retApiResult.code != ApiReturn.CODE_OK:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                      retApiResult.message).toJson())
    return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
示例#5
0
def queryPeopleTaskExecute(request):
    langDict = getLangTextDict(request)
    pageNum = int(request.GET.get("num"))
    attrData = HTTP_task_executeService.queryPeopleTaskExecute(
        pageNum, commonWebConfig.queryPeopleInterface,
        request.session.get("loginName"))
    return HttpResponse(
        ApiReturn(ApiReturn.CODE_OK, langDict["web"]["httpTestCaseSuccess"],
                  attrData).toJson())
示例#6
0
def contrastTaskResult(request):
    context = {}
    taskIds = request.POST.get("taskId")
    taskIdList = taskIds.split(",")
    if len(taskIdList) != 2:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="只能选择两个任务进行比对").toJson())
    ret = HTTP_task_executeService.contrastTask(taskIdList)
    if "code" in ret.keys():
        return HttpResponse(
            ApiReturn(ret["code"], message=ret["message"]).toJson())
    context["taskContrastDict"] = ret
    return render(request, "InterfaceTest/HTTPTask/SubPages/taskContrast.html",
                  context)
示例#7
0
def taskRunAdd(request):
    if VersionService.isCurrentVersion(request):
        taskData = dbModelToDict(
            HTTP_taskService.getTaskForId(request.POST.get("id")))

    else:
        taskData = dbModelToDict(
            HTTP_taskService.getVersionTaskForId(
                request.POST.get("id"),
                VersionService.getVersionName(request)))
        del taskData["versionName_id"]

    del taskData["id"]
    taskData["protocol"] = request.POST.get("protocol")
    taskData["emailList"] = request.POST.get("emailList")
    taskData["addBy_id"] = request.session.get("loginName")
    taskData["addByName"] = request.session.get("userName")
    taskData["isSaveHistory"] = request.POST.get("isSaveHistory")
    taskData["isSendEmail"] = request.POST.get("isSendEmail")
    taskData["execComments"] = request.POST.get("execComments")
    taskData["retryCount"] = request.POST.get("retryCount")
    taskData["execBy_id"] = request.session.get("loginName")
    taskData["execByName"] = request.session.get("userName")
    taskData["version"] = VersionService.getVersionName(request)

    httpConfList = request.POST.get("httpConfKey_id").split(",")

    retmsg = 0

    for httpConfIndex in range(0, len(httpConfList)):
        taskData["httpConfKey_id"] = httpConfList[httpConfIndex]
        taskData["httpConfKeyAlias"] = TbConfigHttp.objects.filter(
            httpConfKey=httpConfList[httpConfIndex])[0].alias
        cres = HTTP_task_executeService.taskRunAdd(taskData)
        addDataResult = dbModelToDict(cres)
        # 将任务执行的信息写入缓存,任务执行的前缀为 taskExecute_executeId
        RedisCache().set_data(
            "%s_taskExecute_%s" % ("HTTP", addDataResult["id"]), "0:0:0:0:0",
            60 * 60 * 12)
        RedisCache().set_data(
            "%s_taskExecuteStatus_%s" % ("HTTP", addDataResult["id"]), "1",
            60 * 60 * 12)
        # tcpin = '{"do":3,"TaskExecuteId":"%s"}' % addDataResult["id"]
        tcpin = '{"do":3,"TaskExecuteId":%s,"TaskExecuteEnv":"%s","TaskId":"%s","protocol":"HTTP"}' % (
            addDataResult["id"], addDataResult["httpConfKey_id"],
            addDataResult["taskId"])
        retApiResult = send_tcp_request(tcpin)
        if retApiResult.code != ApiReturn.CODE_OK:
            retmsg = 1
            RedisCache().del_data("%s_taskExecute_%s" %
                                  ("HTTP", addDataResult["id"]))
            RedisCache().del_data("%s_taskExecuteStatus_%s" %
                                  ("HTTP", addDataResult["id"]))

    if retmsg == 1:
        addUserLog(request, "任务管理->任务执行->任务执行添加成功,但是执行服务出现异常,请联系管理员", "FAIL")
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                      "任务执行添加成功,但是执行服务出现异常,请联系管理员").toJson())
    addUserLog(request, "任务管理->任务执行->成功", "PASS")

    return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())