def taskDel(request):
    id = request.GET.get("id")
    if VersionService.isCurrentVersion(request):
        try:
            taskData = HTTP_taskService.getTaskForId(id)
        except Exception as e:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "参数id错误 %s" % e).toJson())

        if HTTP_taskService.delTaskForId(request, id) == 1:
            return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
        else:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "删除失败,请联系管理员").toJson())
    else:
        try:
            taskData = HTTP_taskService.getVersionTaskById(id)
        except Exception as e:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "参数id错误 %s" % e).toJson())
        # if request.session.get("loginName") != taskData.addBy.loginName:
        #     return HttpResponse(ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, "只能删除自己创建的任务").toJson())

        if HTTP_taskService.delVersionTaskForId(request, id) == 1:
            return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
        else:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "删除失败,请联系管理员").toJson())
def operationTask(request, context):
    langDict = getLangTextDict(request)

    context["option"] = request.GET.get("option")
    context["page"] = 1
    if not isRelease:
        context["env"] = "test"
    try:
        if VersionService.isCurrentVersion(request):
            context["dataAddBy"] = HTTP_taskService.getTaskForId(
                request.GET.get("id")).addBy.loginName
        else:
            context["dataAddBy"] = HTTP_taskService.getVersionTaskForId(
                request.GET.get("id"),
                request.session.get("version")).addBy.loginName

    except Exception as e:
        print(traceback.format_exc())
        return render(request, "permission/page_404.html")

    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    context["id"] = request.GET.get("id")
    context["interfacePage"] = 1
    context["testCasePage"] = 1
    context["taskAdd"] = "current-page"
    text = {}
    text["pageTitle"] = langDict["web"]["httpTaskPageHeadings_%s" %
                                        context["option"]]
    context["text"] = text
    context.update(getServiceConf(request))
    return render(request, "InterfaceTest/HTTPTask/HTTP_taskAdd.html", context)
def taskAddData(request):
    taskData = json.loads(request.body)

    taskData = HTTP_taskService.taskDataToDict(request, taskData)
    taskData["addBy_id"] = request.session.get("loginName")
    taskData["addByName"] = request.session.get("userName")
    if VersionService.isCurrentVersion(request):
        # if "id" not in taskData.keys():
        createTask = HTTP_taskService.addTask(taskData)
        if createTask.id >= 1:
            return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
        else:

            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, "任务保存失败").toJson())
    # else:
    #     taskData["modTime"] = datetime.datetime.now()
    #     editTaskData = HTTP_taskService.editTask(taskData)
    #     if editTaskData == 1:
    #         return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
    #     else:
    #         return HttpResponse(ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, "任务编辑保存失败").toJson())
    else:
        # if "id" not in taskData.keys():
        createTask = HTTP_taskService.addVersionTask(
            taskData, VersionService.getVersionName(request))
        if createTask.id >= 1:
            return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
        else:

            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, "任务保存失败").toJson())
def getTestCaseListDataForTask(request):
    id = request.GET.get("id")
    if VersionService.isCurrentVersion(request):
        taskDataModel = HTTP_taskService.getTaskForId(id)
        taskData = dbModelToDict(taskDataModel)
        getTestCaseDataSql = taskData["taskTestcases"].replace(
            ",",
            "' union all select tht.id,tht.caseId,tht.title,tht.casedesc,tht.stepCount,tht.addBy,tu.userName from tb_http_testcase tht  LEFT JOIN tb_user tu on tht.addBy = tu .loginName where tht.caseId = '"
        )
        sql = "select tht.id,tht.caseId,tht.title,tht.casedesc,tht.stepCount,tht.addBy,tu.userName from tb_http_testcase tht  LEFT JOIN tb_user tu on tht.addBy = tu .loginName where tht.caseId ='%s'" % getTestCaseDataSql
    else:
        taskDataModel = HTTP_taskService.getVersionTaskById(id)
        taskData = dbModelToDict(taskDataModel)
        getTestCaseDataSql = taskData["taskTestcases"].replace(
            ",",
            "' union all select tht.id,tht.caseId,tht.title,tht.casedesc,tht.stepCount,tht.addBy,tu.userName from tb_version_http_testcase tht  LEFT JOIN tb_user tu on tht.addBy = tu .loginName where tht.caseId = '"
        )
        sql = "select tht.id,tht.caseId,tht.title,tht.casedesc,tht.stepCount,tht.addBy,tu.userName from tb_version_http_testcase tht  LEFT JOIN tb_user tu on tht.addBy = tu .loginName where tht.caseId ='%s' and versionName='%s'" % (
            getTestCaseDataSql, VersionService.getVersionName(request))

    taskTestCaseListData = executeSqlGetDict(sql)
    response = render(
        request,
        "InterfaceTest/HTTPTask/SubPages/HTTP_Task_Details_Select_TestCase_list_check_page.html",
        {"pageDatas": taskTestCaseListData})
    return response
def getTaskInterfaceData(taskId,request):
    if VersionService.isCurrentVersion(request):
        taskData = dbModelToDict(HTTP_taskService.getTaskForTaskId(taskId))
    else:
        taskData = dbModelToDict(HTTP_taskService.getVersionTaskForTaskId(taskId,VersionService.getVersionName(request)))

    allInerfaceIdList = []
    allTestCaseIdList = []
    thisTaskInterfaceList = taskData["taskInterfaces"].split(",")
    allInerfaceIdList.extend(thisTaskInterfaceList)
    thisTaskTestCaseList = taskData["taskTestcases"].split(",")
    allTestCaseIdList.extend(thisTaskTestCaseList)

    allInerfaceIdList = list(set(allInerfaceIdList))
    allTestCaseIdList = list(set(allTestCaseIdList))
    allstepIdList = []
    for testCaseIndex in range(0, len(allTestCaseIdList)):
        if VersionService.isCurrentVersion(request):
            thisStepList = HTTP_test_case_stepService.getTestCaseStep(allTestCaseIdList[testCaseIndex])
        else:
            thisStepList = HTTP_test_case_stepService.getVersionTestCaseStep(allTestCaseIdList[testCaseIndex],VersionService.getVersionName(request))

        for stepIndex in range(0, len(thisStepList)):
            allstepIdList.append(thisStepList[stepIndex]["id"])

    if VersionService.isCurrentVersion(request):
        tbName = "tb_http_interface"
        versionCondition = ""
    else:
        tbName = "tb_version_http_interface"
        versionCondition = "and i.versionName='%s'" % request.session.get("version")
    allInterfaceSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName,count(DISTINCT b.bussinessLineName,m.moduleName,i.url ) FROM %s i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.interfaceId in ('%s') %s group by i.url,i.businessLineId,i.moduleId" % (
    tbName,"','".join(allInerfaceIdList),versionCondition)
    allInterfaceData = executeSqlGetDict(allInterfaceSql, [])

    if VersionService.isCurrentVersion(request):
        tbName = "tb_http_testcase_step"
        versionCondition = ""
    else:
        tbName = "tb_version_http_testcase_step"
        versionCondition = "and i.versionName='%s'" % request.session.get("version")
    allStepSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName,count(DISTINCT b.bussinessLineName,m.moduleName,i.url ) FROM %s i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.id in ('%s') %s GROUP BY i.url,i.businessLineId,i.moduleId" % (
    tbName,"','".join((str(i) for i in allstepIdList)),versionCondition)
    allStepData = executeSqlGetDict(allStepSql, [])

    print(len(allInterfaceData))
    print(len(allStepData))
    stepDataLen = len(allStepData)
    for dataIndex in range(0, len(allInterfaceData)):
        stepIndex = 0
        while stepIndex < stepDataLen:
            if allInterfaceData[dataIndex]["businessLineName"] == allStepData[stepIndex]["businessLineName"]:
                if allInterfaceData[dataIndex]["moduleName"] == allStepData[stepIndex]["moduleName"]:
                    if allInterfaceData[dataIndex]["url"] == allStepData[stepIndex]["url"]:
                        del allStepData[stepIndex]
                        stepDataLen = len(allStepData)
            stepIndex += 1
    allInterfaceData.extend(allStepData)
    return allInterfaceData
def taskDelTheSameCase(request):
    id = request.GET.get("id")
    if VersionService.isCurrentVersion(request):
        try:
            taskData = HTTP_taskService.getTaskForId(id)
        except Exception as e:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "参数id错误 %s" % e).toJson())
        if request.session.get("loginName") != taskData.addBy.loginName:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "只能去重自己创建的任务").toJson())

        #开始对task进行去重并保存。

    else:
        try:
            taskData = HTTP_taskService.getVersionTaskById(id)
        except Exception as e:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "参数id错误 %s" % e).toJson())
        if request.session.get("loginName") != taskData.addBy.loginName:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON,
                          "只能去重自己创建的任务").toJson())

        #开始对VersionTask进行去重并保存

    oldTaskInterfaces = taskData.taskInterfaces
    oldInterfaceList = oldTaskInterfaces.split(",")
    newInterfaceList = list(set(oldInterfaceList))
    newInterfaceListStr = ""
    for tmpInterface in newInterfaceList:
        newInterfaceListStr += tmpInterface + ","
    newInterfaceListStr = newInterfaceListStr[:-1]
    taskData.taskInterfaces = newInterfaceListStr

    oldTaskCases = taskData.taskTestcases

    oldCaseList = oldTaskCases.split(",")
    newCaseList = list(set(oldCaseList))
    newCaseStr = ""
    for tmpCase in newCaseList:
        newCaseStr += tmpCase + ","
    newCaseStr = newCaseStr[:-1]
    taskData.taskTestcases = newCaseStr

    try:
        taskData.save(force_update=True)
        return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
    except Exception as e:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_INTERFACE_ERROR, '去重失败!').toJson())
def queryPeopleTask(request):
    langDict = getLangTextDict(request)
    pageNum = int(request.GET.get("num"))
    if VersionService.isCurrentVersion(request):
        attrData = HTTP_taskService.queryPeopleTask(
            pageNum, commonWebConfig.queryPeopleInterface,
            request.session.get("loginName"))
    else:
        attrData = HTTP_taskService.queryVersionPeopleTask(
            pageNum, commonWebConfig.queryPeopleInterface,
            request.session.get("loginName"),
            VersionService.getVersionName(request))
    return HttpResponse(
        ApiReturn(ApiReturn.CODE_OK, langDict["web"]["httpTestCaseSuccess"],
                  attrData).toJson())
Exemple #8
0
def executeIdforTask(request):
    taskId = request.GET.get("taskId", "")
    date = request.GET.get("date", "")
    # 如果date为空,默认查询1天内数据
    if date == "":
        dateTo = datetime.date.today()
        dateFrom = dateTo - datetime.timedelta(days=1)
    else:
        try:
            dateFrom = datetime.datetime.strptime(date, '%Y-%m-%d')
            dateTo = dateFrom + datetime.timedelta(days=1)
        except Exception as e:
            return HttpResponse(
                ApiReturn(code=ApiReturn.CODE_ERROR,
                          message="date格式不正确").toJson())
    executeId = HTTP_taskService.getExecuteIdByTaskId(taskId, dateFrom, dateTo)
    if executeId:
        executeResult = dbModelToDict(executeId)
    else:
        return HttpResponse(
            ApiReturn(code=ApiReturn.CODE_ERROR,
                      message="任务" + taskId + "不存在").toJson())
    return HttpResponse(
        ApiReturn(code=ApiReturn.CODE_ERROR,
                  message="",
                  body={
                      'result': executeResult['testResultMsg']
                  }).toJson())
def mergeTask(request):
    taskIds = request.POST.get("taskId", "")
    taskIdList = taskIds.split(",")

    for index in range(1, len(taskIdList)):
        if taskIdList[0] == taskIdList[index]:
            return HttpResponse(
                ApiReturn(code=ApiReturn.CODE_ERROR,
                          message="副任务中包含主任务,不能合并").toJson())
    tbModule = TbTask.objects.get(taskId=taskIdList[0])
    businessLineList = []
    moduleList = []
    emailList = []
    interfeces = ""
    testCases = ""
    interfaceNum = 0
    sourceList = []
    for index in taskIdList:
        try:
            tmpTaskData = HTTP_taskService.getTaskForTaskId(index)
        except:
            return HttpResponse(
                ApiReturn(code=ApiReturn.CODE_ERROR, message="任务不存在").toJson())
        interfaceNum += tmpTaskData.interfaceNum
        if interfaceNum > commonWebConfig.maxTaskInculedInterfaceNum:
            return HttpResponse(
                ApiReturn(code=ApiReturn.CODE_ERROR,
                          message="合并任务包含总接口数量超过阈值%s,合并失败" %
                          commonWebConfig.maxTaskInculedInterfaceNum).toJson())
        businessLineList.extend(BL_MD_isList(tmpTaskData.businessLineGroup))
        moduleList.extend(BL_MD_isList(tmpTaskData.modulesGroup))
        sourceList.extend(BL_MD_isList(tmpTaskData.sourceGroup))
        if tmpTaskData.emailList != "":
            emailList.extend(tmpTaskData.emailList.split(","))
        if interfeces == "":
            interfeces = tmpTaskData.taskInterfaces
        else:
            interfeces = "%s,%s" % (interfeces, tmpTaskData.taskInterfaces)
        if testCases == "":
            testCases = tmpTaskData.taskTestcases
        else:
            testCases = "%s,%s" % (testCases, tmpTaskData.taskTestcases)
    try:
        #业务线和模块和email去重
        tbModule.businessLineGroup = list(set(businessLineList))
        tbModule.modulesGroup = list(set(moduleList))
        tbModule.taskInterfaces = interfeces
        tbModule.taskTestcases = testCases
        tbModule.interfaceNum = interfaceNum
        tbModule.emailList = ','.join(list(set(emailList)))
        tbModule.sourceGroup = list(set(sourceList))
        tbModule.save()
    except Exception as e:
        return HttpResponse(
            ApiReturn(code=ApiReturn.CODE_ERROR,
                      message="任务合并出错,请联系管理员").toJson())
    return HttpResponse(ApiReturn().toJson())
    def againRunTask(id, addBy, addByName):
        taskExecuteData = dbModelToDict(TbTaskExecute.objects.filter(id=id)[0])
        taskId = taskExecuteData['taskId']
        if taskExecuteData['version'] == "CurrentVersion":
            tmpTask = HTTP_taskService.getTaskForTaskId(taskId)
            if not tmpTask:
                return False
            taskData = dbModelToDict(tmpTask)
            taskData['version'] = "CurrentVersion"
        else:
            tmpTask = HTTP_taskService.getVersionTaskForTaskId(
                taskId, taskExecuteData['version'])
            if not tmpTask:
                return False
            taskData = dbModelToDict(tmpTask)
            del taskData['versionName_id']
            taskData['version'] = taskExecuteData['version']

        if taskData["state"] == 0:
            return False

        del taskData["id"]
        del taskData["addTime"]
        del taskData["modTime"]
        taskData["taskId"] = taskExecuteData["taskId"]
        taskData["addBy_id"] = addBy
        taskData["addByName"] = addByName
        taskData["execBy_id"] = addBy
        taskData["execByName"] = addByName
        taskData["httpConfKey_id"] = taskExecuteData["httpConfKey_id"]
        taskData["httpConfKeyAlias"] = taskExecuteData["httpConfKeyAlias"]
        taskData["isSaveHistory"] = taskExecuteData["isSaveHistory"]
        taskData["isSendEmail"] = taskExecuteData["isSendEmail"]
        taskData["execComments"] = taskExecuteData["execComments"]
        taskData["retryCount"] = taskExecuteData["retryCount"]
        taskData["testResultMsg"] = ""
        taskData["performanceResult"] = "N/A"
        taskData["modBy"] = addBy
        taskData["modByName"] = addByName
        addResult = TbTaskExecute.objects.create(**taskData)
        return addResult
def taskDataSaveEdit(request):
    taskData = json.loads(request.body)

    taskData = HTTP_taskService.taskDataToDict(request, taskData)

    if VersionService.isCurrentVersion(request):
        taskData["modTime"] = datetime.datetime.now()
        editTaskData = HTTP_taskService.editTask(taskData)
        if editTaskData == 1:
            return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
        else:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, "任务编辑保存失败").toJson())
    else:
        taskData["modTime"] = datetime.datetime.now()
        editTaskData = HTTP_taskService.editVersionTask(
            taskData, VersionService.getVersionName(request))
        if editTaskData == 1:
            return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
        else:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_TASK_EXCEPITON, "任务编辑保存失败").toJson())
def getTaskForId(request):
    langDict = getLangTextDict(request)
    id = request.GET.get("id")
    if VersionService.isCurrentVersion(request):
        taskData = HTTP_taskService.getTaskForId(id)
    else:
        taskData = HTTP_taskService.getVersionTaskForId(
            id, VersionService.getVersionName(request))

    if not taskData:
        return HttpResponse(ApiReturn(ApiReturn.CODE_TASK_EXCEPITON).toJson())
    taskDataDict = dbModelToDict(taskData)
    taskDataUser = dbModelToDict(taskData.addBy)
    del taskDataUser["id"]
    taskDataDict.update(taskDataUser)
    context = {}
    context.update(getServiceConf(request))
    context["httpConf"] = HttpConfService.queryHttpConfSort(request)
    context["taskData"] = taskDataDict
    context["option"] = request.GET.get("option")
    return render(request,
                  "InterfaceTest/HTTPTask/SubPages/task_Run_DetailsPage.html",
                  context)
def getTaskData(request):
    id = request.GET.get("id")

    if VersionService.isCurrentVersion(request):
        taskDataModel = HTTP_taskService.findTaskForId(id)[0]
        taskData = dbModelToDict(taskDataModel)
        serviceConf = ServiceConfService.queryServiceConfSort(request)
        highPriorityVARS = taskData["highPriorityVARS"]
        taskData["priorityCommon"] = substr(highPriorityVARS, "[CONF=common]",
                                            "[ENDCONF]")
        taskData["confPriority"] = {}
        for i in range(0, len(serviceConf)):
            if serviceConf[i]["serviceConfKey"] not in highPriorityVARS:
                taskData["confPriority"]["priority%s" %
                                         serviceConf[i]["serviceConfKey"]] = ""
                continue
            taskData["confPriority"][
                "priority%s" % serviceConf[i]["serviceConfKey"]] = substr(
                    highPriorityVARS,
                    "[CONF=%s]" % serviceConf[i]["serviceConfKey"],
                    "[ENDCONF]")
        taskData["interfaceList"] = []
        if taskData["taskInterfaces"]:
            taskInterfaceList = taskData["taskInterfaces"].split(",")
            for i in range(0, len(taskInterfaceList)):
                try:
                    thisInterface = HTTP_interfaceService.getInterfaceForInterfaceId(
                        taskInterfaceList[i])
                    if not thisInterface:
                        continue
                    taskData["interfaceList"].append(
                        dbModelToDict(thisInterface))
                    addBy = dbModelToDict(thisInterface.addBy)
                    del addBy["id"]
                    del addBy["state"]
                    taskData["interfaceList"][i].update(addBy)
                    # print( taskData["interfaceList"][i])
                except Exception as e:
                    # print(addBy)
                    # taskData["interfaceList"][i].update(addBy)
                    taskData["interfaceList"].append('')
                    continue
        taskData["testCaseList"] = []
        if taskData["taskTestcases"]:
            taskTestCaseList = taskData["taskTestcases"].split(",")
            for i in range(0, len(taskTestCaseList)):
                try:
                    thisTestCase = HTTP_test_caseService.getTestCaseForTestCaseId(
                        taskTestCaseList[i])
                    taskData["testCaseList"].append(
                        dbModelToDict(thisTestCase))
                    addBy = dbModelToDict(thisTestCase.addBy)
                    del addBy["id"]
                    del addBy["state"]
                    taskData["testCaseList"][i].update(addBy)
                except Exception as e:
                    taskData["interfaceList"].append('')
                    continue
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_OK, body=taskData).toJson())
    else:
        taskDataModel = HTTP_taskService.findVersionTaskForId(
            id, VersionService.getVersionName(request))[0]
        taskData = dbModelToDict(taskDataModel)
        serviceConf = ServiceConfService.queryServiceConfSort(request)
        highPriorityVARS = taskData["highPriorityVARS"]
        taskData["priorityCommon"] = substr(highPriorityVARS, "[CONF=common]",
                                            "[ENDCONF]")
        taskData["confPriority"] = {}
        for i in range(0, len(serviceConf)):
            if serviceConf[i]["serviceConfKey"] not in highPriorityVARS:
                taskData["confPriority"]["priority%s" %
                                         serviceConf[i]["serviceConfKey"]] = ""
                continue
            taskData["confPriority"][
                "priority%s" % serviceConf[i]["serviceConfKey"]] = substr(
                    highPriorityVARS,
                    "[CONF=%s]" % serviceConf[i]["serviceConfKey"],
                    "[ENDCONF]")
        taskData["interfaceList"] = []
        if taskData["taskInterfaces"]:
            taskInterfaceList = taskData["taskInterfaces"].split(",")
            for i in range(0, len(taskInterfaceList)):
                try:
                    thisInterface = HTTP_interfaceService.getVersionInterfaceForInterfaceId(
                        taskInterfaceList[i],
                        VersionService.getVersionName(request))
                    if not thisInterface:
                        continue
                    taskData["interfaceList"].append(
                        dbModelToDict(thisInterface))
                    addBy = dbModelToDict(thisInterface.addBy)
                    del addBy["id"]
                    del addBy["state"]
                    taskData["interfaceList"][i].update(addBy)
                    # print( taskData["interfaceList"][i])
                except Exception as e:
                    # print(addBy)
                    # taskData["interfaceList"][i].update(addBy)
                    taskData["interfaceList"].append('')
                    continue
        taskData["testCaseList"] = []
        if taskData["taskTestcases"]:
            taskTestCaseList = taskData["taskTestcases"].split(",")
            for i in range(0, len(taskTestCaseList)):
                try:
                    thisTestCase = HTTP_test_caseService.getVersionTestCaseForTestCaseId(
                        taskTestCaseList[i],
                        VersionService.getVersionName(request))
                    taskData["testCaseList"].append(
                        dbModelToDict(thisTestCase))
                    addBy = dbModelToDict(thisTestCase.addBy)
                    del addBy["id"]
                    del addBy["state"]
                    taskData["testCaseList"][i].update(addBy)
                except Exception as e:
                    taskData["interfaceList"].append('')
                    continue
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_OK, body=taskData).toJson())
Exemple #14
0
def getCoverage(resultDict, taskIdList, businessLine, module):
    if businessLine not in resultDict.keys():
        resultDict[businessLine] = {}
    # 标准接口
    standardSql = "SELECT i.interfaceUrl url,m.moduleName moduleName,b.bussinessLineName businessLineName,u.userName userName FROM tb_standard_interface i LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_business_line b ON i.businessLineId = b.id  LEFT JOIN tb_user u ON i.addBy = u.loginName WHERE 1=1 AND i.state=1"
    if businessLine != "":
        standardSql = '%s and b.bussinessLineName = "%s"' % (standardSql,
                                                             businessLine)
    if module != "":
        standardSql = "%s and m.moduleName = '%s'" % (standardSql, module)
    standardData = executeSqlGetDict(standardSql, [])
    for dataIndex in standardData:
        dataIndex["standardIsCovered"] = False

    standardDataDict = {}

    # 生成标准dict
    for tmpInterfaceDict in standardData:
        tmpBusinessLine = tmpInterfaceDict['businessLineName']

        if tmpBusinessLine not in standardDataDict.keys():
            standardDataDict[tmpBusinessLine] = {
                "dataList": [],
                "businessLineCount": 0,
                "businessLineIsCoveredCount": 0,
                "moduleDict": {}
            }
        standardDataDict[tmpBusinessLine]['dataList'].append(tmpInterfaceDict)
        standardDataDict[tmpBusinessLine]['businessLineCount'] += 1

    taskList = dbModelListToListDict(
        HTTP_taskService.getTaskListForTaskIdList(taskIdList))
    allInerfaceIdList = []
    allTestCaseIdList = []
    for taskIndex in range(0, len(taskList)):
        thisTaskInterfaceList = taskList[taskIndex]["taskInterfaces"].split(
            ",")
        allInerfaceIdList.extend(thisTaskInterfaceList)
        thisTaskTestCaseList = taskList[taskIndex]["taskTestcases"].split(",")
        allTestCaseIdList.extend(thisTaskTestCaseList)

    #场景总数
    resultDict[businessLine]["testCaseSum"] = len(allTestCaseIdList)

    allInerfaceIdList = list(set(allInerfaceIdList))
    allTestCaseIdList = list(set(allTestCaseIdList))
    allstepIdList = []
    allstepList = HTTP_test_case_stepService.getTestCaseStepList(
        allTestCaseIdList)
    for stepIndex in range(0, len(allstepList)):
        allstepIdList.append(allstepList[stepIndex]["id"])

    #获取没去重的接口和步骤数量
    allInterfaceNotDistinctSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName FROM tb_http_interface i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.caseType in (1,2) and i.interfaceId in ('%s') group by i.url,i.businessLineId,i.moduleId" % (
        "','".join(allInerfaceIdList))
    allInterfaceNotDistinctData = executeSqlGetDict(allInterfaceNotDistinctSql,
                                                    [])
    allStepNotDisTinctSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName FROM tb_http_testcase_step i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.caseType in (2,3) and i.id in ('%s') group by i.url,i.businessLineId,i.moduleId" % (
        "','".join((str(i) for i in allstepIdList)))
    allStepNotDisTinctData = executeSqlGetDict(allStepNotDisTinctSql, [])
    #设置没去重的用例总数
    resultDict[businessLine]["executeInterfaceSum"] = len(
        allInterfaceNotDistinctData) + len(allStepNotDisTinctData)

    allInterfaceSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName,count(DISTINCT b.bussinessLineName,m.moduleName,i.url ) FROM tb_http_interface i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.caseType in (1,2) and i.interfaceId in ('%s') group by i.url,i.businessLineId,i.moduleId" % (
        "','".join(allInerfaceIdList))
    allInterfaceData = executeSqlGetDict(allInterfaceSql, [])
    allStepSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName,count(DISTINCT b.bussinessLineName,m.moduleName,i.url ) FROM tb_http_testcase_step i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.caseType in (2,3) and i.id in ('%s') group by i.url,i.businessLineId,i.moduleId" % (
        "','".join((str(i) for i in allstepIdList)))
    allStepData = executeSqlGetDict(allStepSql, [])
    # 接口和步骤去重
    stepDataLen = len(allStepData)
    for dataIndex in range(0, len(allInterfaceData)):
        stepIndex = 0
        while stepIndex < stepDataLen:
            if allInterfaceData[dataIndex]["businessLineName"] == allStepData[
                    stepIndex]["businessLineName"]:
                if allInterfaceData[dataIndex]["moduleName"] == allStepData[
                        stepIndex]["moduleName"]:
                    if allInterfaceData[dataIndex]["url"] == allStepData[
                            stepIndex]["url"]:
                        del allStepData[stepIndex]
                        stepDataLen = len(allStepData)
            stepIndex += 1
    allInterfaceData.extend(allStepData)
    # 生成用户数据dict
    allDataDict = {}
    for tmpInterfaceDict in allInterfaceData:
        tmpInterfaceDict["standardIsCovered"] = False
        tmpBusinessLine = tmpInterfaceDict['businessLineName']
        if tmpBusinessLine not in allDataDict.keys():
            allDataDict[tmpBusinessLine] = {
                "dataList": [],
                "businessLineCount": 0,
                "businessLineIsCoveredCount": 0
            }
        allDataDict[tmpBusinessLine]['dataList'].append(tmpInterfaceDict)
        allDataDict[tmpBusinessLine]['businessLineCount'] += 1

    resultDict[businessLine]["allDataCount"] = len(allInterfaceData)
    resultDict[businessLine]["coverCount"] = 0  # 执行后生成
    resultDict[businessLine]["notCoverCount"] = 0  # 执行后还要重算
    resultDict[businessLine]["notStandardCount"] = 0  # 执行后还要重算
    for standardBLineKey, standardBLineValue in standardDataDict.items():
        # 遍历自己的业务线datalist生成业务线的覆盖率统计
        if standardBLineKey not in allDataDict:
            allDataDict[standardBLineKey] = {
                "dataList": [],
                "businessLineCount": 0,
                "businessLineIsCoveredCount": 0,
                "moduleDict": {}
            }
            continue
        # 先循环判断当期业务线的数据统计
        allBLineValue = allDataDict[standardBLineKey]
        for tmpAllUrlDict in allBLineValue['dataList']:
            for tmpStandardUrlDict in standardBLineValue['dataList']:
                if checkUrl(tmpStandardUrlDict['url']) == checkUrl(
                        tmpAllUrlDict['url']
                ) and tmpStandardUrlDict['businessLineName'] == tmpAllUrlDict[
                        'businessLineName'] and tmpStandardUrlDict[
                            'moduleName'] == tmpAllUrlDict['moduleName']:
                    tmpStandardUrlDict["standardIsCovered"] = True
                    tmpAllUrlDict["dataIsCovered"] = True
                    standardBLineValue["businessLineIsCoveredCount"] += 1
                    resultDict[businessLine]["coverCount"] += 1
                    continue

    resultDict[businessLine]["notCoverCount"] = len(
        standardData) - resultDict[businessLine]["coverCount"]
    resultDict[businessLine]["notStandardCount"] = len(
        allInterfaceData) - resultDict[businessLine]["coverCount"]
    #
    # #平台接口总数量
    # platformInterfaceNum = len(TbHttpInterface.objects.filter(caseType__in=[1,2]).filter(state=1))+len(TbHttpTestcaseStep.objects.filter(caseType__in=[2,3]).filter(state=1))
    #
    # #接口平均用例数
    # interfaceAverageTestCaseNum = round(platformInterfaceNum / standardCount)
    #
    #标准任务数量
    #
    #标准任务已覆盖接口数量
    standardTaskList = dbModelListToListDict(TbWebPortalTask.objects.filter(state=1))
    standardTaskIdList = []
    for index in standardTaskList:
        standardTaskIdList.append(index["taskId"])
    print("standardTaskIdList:", standardTaskIdList)
    taskList = dbModelListToListDict(HTTP_taskService.getTaskListForTaskIdList(standardTaskIdList))
    print("taskList:", taskList)
    allInerfaceIdList = []
    allTestCaseIdList = []
    for taskIndex in range(0, len(taskList)):
        thisTaskInterfaceList = taskList[taskIndex]["taskInterfaces"].split(",")
        allInerfaceIdList.extend(thisTaskInterfaceList)
        thisTaskTestCaseList = taskList[taskIndex]["taskTestcases"].split(",")
        allTestCaseIdList.extend(thisTaskTestCaseList)

    allInerfaceIdList = list(set(allInerfaceIdList))
    allTestCaseIdList = list(set(allTestCaseIdList))
    print("allInerfaceIdList:", allInerfaceIdList)

    t4 = time.time()
    # print("[通过caseIdList获取所有步骤]t4-t3:%f" % (t4 - t3))
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())
def srcTaskFileCoverList(request):
    t0 = time.time()
    if request.POST.get("taskList"):
        taskIdList = request.POST.get("taskList").split(",")
    else:
        selflastTask = dbModelListToListDict(HTTP_taskService.getUserLastTask(request.session.get("loginName")))
        if len(selflastTask) < 1:
            response = render(request, "InterfaceTest/src_file_analyze/SubPages/src_task_file_cover_sub_page.html",{})
            return response
        taskIdList = [selflastTask[-1]["taskId"]]

    t1 = time.time()
    print("[查询任务list]t1-t0:%f" % (t1-t0))
    if VersionService.isCurrentVersion(request):
        taskList = dbModelListToListDict(HTTP_taskService.getTaskListForTaskIdList(taskIdList))
    else:
        taskList = dbModelListToListDict(HTTP_taskService.getVersionTaskListForTaskIdList(taskIdList,VersionService.getVersionName(request)))

    t2 = time.time()
    print("[查询所有任务]t2-t1:%f" % (t2-t1))
    allInerfaceIdList = []
    allTestCaseIdList = []
    for taskIndex in range(0,len(taskList)):
        thisTaskInterfaceList = taskList[taskIndex]["taskInterfaces"].split(",")
        allInerfaceIdList.extend(thisTaskInterfaceList)
        thisTaskTestCaseList = taskList[taskIndex]["taskTestcases"].split(",")
        allTestCaseIdList.extend(thisTaskTestCaseList)

    allInerfaceIdList = list(set(allInerfaceIdList))
    allTestCaseIdList = list(set(allTestCaseIdList))
    allstepIdList = []
    t3 = time.time()
    print("[去重任务中的接口和用例]t3-t2:%f" % (t3-t2))

    if VersionService.isCurrentVersion(request):
        allstepList = HTTP_test_case_stepService.getTestCaseStepList(allTestCaseIdList)
    else:
        allstepList = HTTP_test_case_stepService.getVersionTestCaseStepList(allTestCaseIdList,VersionService.getVersionName(request))
    for stepIndex in range(0, len(allstepList)):
        allstepIdList.append(allstepList[stepIndex]["id"])
    t4 = time.time()
    print("[通过caseIdList获取所有步骤]t4-t3:%f" % (t4-t3))

    if VersionService.isCurrentVersion(request):
        tbName = "tb_http_interface"
        versionCondition = ""
    else:
        tbName = "tb_version_http_interface"
        versionCondition = "and i.versionName='%s'" % request.session.get("version")
    allInterfaceSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName,count(DISTINCT b.bussinessLineName,m.moduleName,i.url ) FROM %s i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.caseType in (1,2) and i.interfaceId in ('%s') %s group by i.url,i.businessLineId,i.moduleId" % (tbName,"','".join(allInerfaceIdList),versionCondition)
    allInterfaceData = executeSqlGetDict(allInterfaceSql,[])

    if VersionService.isCurrentVersion(request):
        tbName = "tb_http_testcase_step"
        versionCondition = ""
    else:
        tbName = "tb_version_http_testcase_step"
        versionCondition = "and i.versionName='%s'" % request.session.get("version")
    allStepSql = "SELECT i.url url,b.bussinessLineName businessLineName,m.moduleName moduleName,u.userName userName,count(DISTINCT b.bussinessLineName,m.moduleName,i.url ) FROM %s i LEFT JOIN tb_business_line b ON i.businessLineId = b.id LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_user u ON i.addBy = u.loginName where i.state = 1 and i.caseType in (2,3) and i.id in ('%s') %s GROUP BY i.url,i.businessLineId,i.moduleId" % (tbName,"','".join((str(i) for i in allstepIdList)),versionCondition)
    allStepData = executeSqlGetDict(allStepSql,[])
    t5 = time.time()
    print("[查询接口和步骤]t5-t4:%f" % (t5-t4))
    print(len(allInterfaceData))
    print(len(allStepData))

    #接口和步骤去重
    stepDataLen = len(allStepData)
    for dataIndex in range(0, len(allInterfaceData)):
        stepIndex = 0
        while stepIndex < stepDataLen:
            if allInterfaceData[dataIndex]["businessLineName"] == allStepData[stepIndex]["businessLineName"]:
                if allInterfaceData[dataIndex]["moduleName"] == allStepData[stepIndex]["moduleName"]:
                    if allInterfaceData[dataIndex]["url"] == allStepData[stepIndex]["url"]:
                        del allStepData[stepIndex]
                        stepDataLen = len(allStepData)
            stepIndex += 1
    allInterfaceData.extend(allStepData)
    print(len(allInterfaceData))
    t6= time.time()
    print("[去重接口和步骤]t6-t5:%f" % (t6-t5))

    if VersionService.isCurrentVersion(request):
        tbName = "tb_standard_interface"
        versionCondition = ""
    else:
        tbName = "tb_version_standard_interface"
        versionCondition = "and i.versionName='%s'" % request.session.get("version")
    standardSql = "SELECT i.interfaceUrl url,m.moduleName moduleName,b.bussinessLineName businessLineName,u.userName userName FROM %s i LEFT JOIN tb_modules m ON i.moduleId = m.id LEFT JOIN tb_business_line b ON i.businessLineId = b.id  LEFT JOIN tb_user u ON i.addBy = u.loginName WHERE 1=1 AND i.apiStatus = 1 AND i.state=1 %s GROUP BY i.interfaceUrl,i.businessLineId,i.moduleId" % (tbName,versionCondition)
    standardData = executeSqlGetDict(standardSql,[])
    t7= time.time()
    print("[查询标准]t7-t6:%f" % (t7-t6))

    for dataIndex in standardData:
        dataIndex["standardIsCovered"] = False
    t71= time.time()
    print("[生成标准dict]t71-t7:%f" % (t71-t7))
    #生成用户数据dict
    allDataDict = {}
    for tmpInterfaceDict in allInterfaceData:
        tmpInterfaceDict["standardIsCovered"] = False
        tmpBusinessLine = tmpInterfaceDict['businessLineName']
        tmpModule = tmpInterfaceDict['moduleName']
        if tmpBusinessLine not in allDataDict.keys():
            allDataDict[tmpBusinessLine] = {"dataList": [], "businessLineCount": 0, "businessLineIsCoveredCount": 0,"businessLineStandardCount":0,"moduleDict": {},"queryBL":True}
        allDataDict[tmpBusinessLine]['dataList'].append(tmpInterfaceDict)
        allDataDict[tmpBusinessLine]['businessLineCount'] += 1
        if tmpModule not in allDataDict[tmpBusinessLine]['moduleDict'].keys():
            allDataDict[tmpBusinessLine]['moduleDict'][tmpModule] = {"dataList": [], "moduleCount": 0,"moduleStandardCount":0, "moduleIsCoveredCount": 0,"queryMD":True}
        allDataDict[tmpBusinessLine]['moduleDict'][tmpModule]['dataList'].append(tmpInterfaceDict)
        allDataDict[tmpBusinessLine]['moduleDict'][tmpModule]['moduleCount'] += 1
    t72= time.time()
    print("[生成用户数据dict]t72-t71:%f" % (t72-t71))

    standardDataDict = {}
    # 生成标准dict
    for tmpInterfaceDict in standardData:
        tmpBusinessLine = tmpInterfaceDict['businessLineName']
        tmpModule = tmpInterfaceDict['moduleName']
        if tmpBusinessLine not in allDataDict.keys():
            continue
        if tmpBusinessLine not in standardDataDict.keys():
            standardDataDict[tmpBusinessLine] = {"dataList": [], "businessLineCount": 0,"businessLineIsCoveredCount": 0, "moduleDict": {}}
        standardDataDict[tmpBusinessLine]['dataList'].append(tmpInterfaceDict)
        standardDataDict[tmpBusinessLine]['businessLineCount'] += 1
        allDataDict[tmpBusinessLine]['businessLineStandardCount'] += 1
        if tmpModule not in allDataDict[tmpBusinessLine]['moduleDict'].keys():
            continue
        if tmpModule not in standardDataDict[tmpBusinessLine]['moduleDict'].keys():
            standardDataDict[tmpBusinessLine]['moduleDict'][tmpModule] = {"dataList": [], "moduleCount": 0,"moduleIsCoveredCount": 0}
        standardDataDict[tmpBusinessLine]['moduleDict'][tmpModule]['dataList'].append(tmpInterfaceDict)
        standardDataDict[tmpBusinessLine]['moduleDict'][tmpModule]['moduleCount'] += 1
        allDataDict[tmpBusinessLine]['moduleDict'][tmpModule]['moduleStandardCount'] += 1
    # 开始遍历标准字典了!为了给是否覆盖的tag改为True
    coverCount = 0 #不用用同一个名字!!如果用同一个名字,要分清楚哪里要还原为0!
    allDataStatistics = {}
    allDataStatistics["allDataCount"] = len(allInterfaceData)
    allDataStatistics["standardCount"] = len(standardData)
    allDataStatistics["coverCount"] = 0 #执行后生成
    allDataStatistics["notCoverCount"] = 0  #执行后还要重算
    allDataStatistics["notStandardCount"] = len(allInterfaceData) - coverCount  #执行后还要重算
    for standardBLineKey, standardBLineValue in standardDataDict.items():
        # 遍历自己的业务线datalist生成业务线的覆盖率统计
        if standardBLineKey not in allDataDict:
            allDataDict[standardBLineKey] = {"dataList": [], "businessLineCount": 0, "businessLineIsCoveredCount": 0,"moduleDict": {}}
        #先循环判断当期业务线的数据统计
        allBLineValue = allDataDict[standardBLineKey]
        for tmpStandardUrlDict in standardBLineValue['dataList']:
            for tmpAllUrlDict in allBLineValue['dataList']:
                if checkUrl(tmpStandardUrlDict['url']) == checkUrl(tmpAllUrlDict['url']) and tmpStandardUrlDict['moduleName'] == tmpAllUrlDict['moduleName']:
                    tmpStandardUrlDict["standardIsCovered"] = True
                    tmpAllUrlDict["dataIsCovered"] = True
                    tmpStandardUrlDict["dataUrl"] = tmpAllUrlDict['url']
                    allBLineValue["businessLineIsCoveredCount"] += 1
                    allDataStatistics["coverCount"] += 1
        #在判断当前业务线线下的modelDict的统计
        tmpStandardModuleDict = standardDataDict[standardBLineKey]["moduleDict"]
        for standardModuleKey, standardModuleValue in tmpStandardModuleDict.items():
            if standardModuleKey not in allDataDict[standardBLineKey]["moduleDict"]:
                allDataDict[standardBLineKey]["moduleDict"][standardModuleKey] = {"dataList": [], "moduleCount": 0,"moduleIsCoveredCount": 0}
                allDataDict[standardBLineKey]["moduleDict"][standardModuleKey]["queryMD"] = False
                continue
            allMdValue = allDataDict[standardBLineKey]["moduleDict"][standardModuleKey]["dataList"]
            for tmpStandardMdDict in tmpStandardModuleDict[standardModuleKey]["dataList"]:
                for tmpAllMdDict in allMdValue:
                    if checkUrl(tmpStandardMdDict["url"]) == checkUrl(tmpAllMdDict["url"]):
                        tmpStandardMdDict["standardIsCovered"] = True
                        tmpAllMdDict["dataIsCovered"] = True
                        tmpStandardMdDict["dataUrl"] = tmpAllMdDict["url"]
                        allDataDict[standardBLineKey]["moduleDict"][standardModuleKey]["moduleIsCoveredCount"] += 1

    allDataStatistics["notCoverCount"] = allDataStatistics["standardCount"] - allDataStatistics["coverCount"]  # 执行后还要重算
    allDataStatistics["notStandardCount"] = len(allInterfaceData) - allDataStatistics["coverCount"]   # 执行后还要重算
    coverage = '%.2f' % 0
    if allDataStatistics["standardCount"] != 0:
        coverage = '%.2f' % (allDataStatistics["coverCount"] / allDataStatistics["standardCount"] * 100)
    allDataStatistics["coverage"] = coverage

    #生成覆盖tag后开始计算覆盖率所有数据的覆盖率
    for standardKey,standardValue in standardDataDict.items():
        for dataKey,dataValue in allDataDict.items():
            if dataKey == standardKey:
                dataValue["businessCovered"] = '%.2f' % 0
                dataValue["businessNotCovered"] = dataValue["businessLineStandardCount"] - dataValue["businessLineIsCoveredCount"]
                if dataValue["businessLineCount"] != 0:
                    dataValue["businessCovered"] = '%.2f' % (dataValue["businessLineIsCoveredCount"] / dataValue["businessLineStandardCount"] * 100)
                else:
                    dataValue["businessCovered"] = '%.2f' % 0
                for dataModuleKey,dataModuleValue in dataValue["moduleDict"].items():
                        dataModuleValue["moduleNotCoveredCount"] = dataModuleValue["moduleStandardCount"] - dataModuleValue["moduleIsCoveredCount"]
                        if dataModuleValue["moduleStandardCount"] != 0:
                            dataModuleValue["moduleCovered"] = '%.2f' % (dataModuleValue["moduleIsCoveredCount"] / dataModuleValue["moduleStandardCount"] * 100)
                        else:
                            dataModuleValue["moduleCovered"] = '%.2f' % 0
    context = {}
    context["allDataStatistics"] = allDataStatistics
    context["standardDataDict"] = standardDataDict
    context["dataDict"] = allDataDict

    #生成任务的字典
    taskDict = {}
    for taskIndex in range(0,len(taskList)):
        thisTaskData = getTaskInterfaceData(taskList[taskIndex]["taskId"],request)
        print(len(thisTaskData))
        for dataIndex in thisTaskData:
            dataIndex["isCovered"] = False
        taskDict[taskList[taskIndex]["taskId"]] = {"taskInterfaceCount":len(thisTaskData),
                                                   "taskDataList":thisTaskData,
                                                   "taskIsCoveredCount":0,
                                                   "taskContainsBl":{},
                                                   "standardDataList":deepcopy(standardData)}
        taskDict[taskList[taskIndex]["taskId"]]["coverage"] = '%.2f' % 0.00
        tmpBlDict = taskDict[taskList[taskIndex]["taskId"]]["taskContainsBl"]
        for tmpBlIndex in thisTaskData:
            if tmpBlIndex["businessLineName"] not in tmpBlDict:
                tmpBlDict[tmpBlIndex["businessLineName"]] = {"blCount":0,"blDataList":[],"blIsCoveredCount":0,"blContainsMd":{},"standardDataList":[],"standardBlCount":0,"blNotCoveredCount":0}
                tmpBlDict[tmpBlIndex["businessLineName"]]["blCoverage"] = '%.2f' % 0.00
            tmpBlDict[tmpBlIndex["businessLineName"]]["blCount"] += 1
            tmpBlDict[tmpBlIndex["businessLineName"]]["blDataList"].append(deepcopy(tmpBlIndex))
            for standardIndex in standardData:
                if standardIndex["businessLineName"] == tmpBlIndex["businessLineName"]:
                    tmpBlDict[tmpBlIndex["businessLineName"]]["standardDataList"].append(deepcopy(standardIndex))

            tmpMd = tmpBlDict[tmpBlIndex["businessLineName"]]["blContainsMd"]
            if tmpBlIndex["moduleName"] not in tmpMd:
                tmpMd[tmpBlIndex["moduleName"]] = {"mdCount":0,"mdDataList":[],"mdIsCoveredCount":0,"standardDataList":[],"standardMdCount":0,"mdNotCoveredCount":0}
                tmpMd[tmpBlIndex["moduleName"]]["mdCoverage"] = '%.2f' % 0.00
            tmpMd[tmpBlIndex["moduleName"]]["mdCount"] += 1
            tmpMd[tmpBlIndex["moduleName"]]["mdDataList"].append(deepcopy(tmpBlIndex))
            for standardIndex in standardData:
                if standardIndex["moduleName"] == tmpBlIndex["moduleName"] and standardIndex["businessLineName"] == tmpBlIndex["businessLineName"]:
                    tmpMd[tmpBlIndex["moduleName"]]["standardDataList"].append(deepcopy(standardIndex))

    t75 = time.time()
    #开始生成任务的覆盖率了!
    for tmpTaskKey,tmpTaskValue in taskDict.items():
        for taskDataIndex in tmpTaskValue["taskDataList"]:
            for standardIndex in standardData:
                if checkUrl(taskDataIndex["url"]) == checkUrl(standardIndex["url"]) and taskDataIndex["businessLineName"] == standardIndex["businessLineName"] and taskDataIndex["moduleName"] == standardIndex["moduleName"]:
                    taskDataIndex["isCovered"] = True
                    tmpTaskValue["taskIsCoveredCount"] += 1
                    for taskStandardDataIndex in tmpTaskValue["standardDataList"]:
                        if checkUrl(taskStandardDataIndex["url"]) == checkUrl(standardIndex["url"]) and taskStandardDataIndex["businessLineName"] == standardIndex["businessLineName"] and taskStandardDataIndex["moduleName"] == standardIndex["moduleName"]:
                            taskStandardDataIndex["standardIsCovered"] = True
                            taskStandardDataIndex["dataUrl"] = standardIndex["url"]

        for tmpTaskBlKey,tmpTaskBlValue in tmpTaskValue["taskContainsBl"].items():
            for tmpTaskBlDataIndex in tmpTaskBlValue["blDataList"]:
                for standardIndex in standardData:
                    if checkUrl(tmpTaskBlDataIndex["url"]) == checkUrl(standardIndex["url"]) and tmpTaskBlDataIndex["businessLineName"] == standardIndex[
                        "businessLineName"] and tmpTaskBlDataIndex["moduleName"] == standardIndex["moduleName"]:
                        tmpTaskBlDataIndex["isCovered"] = True
                        tmpTaskBlValue["blIsCoveredCount"] += 1
                        for taskStandardDataIndex in tmpTaskBlValue["standardDataList"]:
                            if checkUrl(taskStandardDataIndex["url"]) == checkUrl(standardIndex["url"]) and taskStandardDataIndex[
                                "businessLineName"] == standardIndex[
                                "businessLineName"] and taskStandardDataIndex["moduleName"] == standardIndex["moduleName"]:
                                taskStandardDataIndex["standardIsCovered"] = True
                                taskStandardDataIndex["dataUrl"] = standardIndex["url"]
            for tmpTaskMdKey,tmpTaskMdValue in tmpTaskBlValue["blContainsMd"].items():
                for tmpTaskMdDataIndex in tmpTaskMdValue["mdDataList"]:
                    for standardIndex in standardData:
                        if checkUrl(tmpTaskMdDataIndex["url"]) == checkUrl(standardIndex["url"]) and tmpTaskMdDataIndex[
                            "businessLineName"] == standardIndex[
                            "businessLineName"] and tmpTaskMdDataIndex["moduleName"] == standardIndex["moduleName"]:
                            tmpTaskMdDataIndex["isCovered"] = True
                            tmpTaskMdValue["mdIsCoveredCount"] += 1
                            for taskStandardDataIndex in tmpTaskMdValue["standardDataList"]:
                                if checkUrl(taskStandardDataIndex["url"]) == checkUrl(standardIndex["url"]) and taskStandardDataIndex[
                                    "businessLineName"] == standardIndex[
                                    "businessLineName"] and taskStandardDataIndex["moduleName"] == standardIndex[
                                    "moduleName"]:
                                    taskStandardDataIndex["standardIsCovered"] = True
                                    taskStandardDataIndex["dataUrl"] = standardIndex["url"]

    t76 = time.time()
    print("[生成任务覆盖率]t76-t75:%f" % (t76 - t75))

    #计算覆盖率
    standardDataCount = len(standardData)
    for tmpTaskKey,tmpTaskValue in taskDict.items():
        tmpTaskValue["standardDataCount"] = standardDataCount
        tmpTaskValue["notCoveredCount"] = standardDataCount - tmpTaskValue["taskIsCoveredCount"]
        tmpTaskValue["notStandardCount"] = tmpTaskValue["taskInterfaceCount"] - tmpTaskValue["taskIsCoveredCount"]
        if standardDataCount != 0:
            tmpTaskValue["coverage"] = '%.2f' % (tmpTaskValue["taskIsCoveredCount"] / standardDataCount * 100)
        for tmpTaskBlKey, tmpTaskBlValue in tmpTaskValue["taskContainsBl"].items():
            tmpTaskBlValue["notStandardCount"] = tmpTaskBlValue["blCount"] - tmpTaskBlValue["blIsCoveredCount"]
            if tmpTaskBlKey in standardDataDict.keys():
                tmpTaskBlValue["standardBlCount"] = standardDataDict[tmpTaskBlKey]["businessLineCount"]
                tmpTaskBlValue["blNotCoveredCount"] = tmpTaskBlValue["standardBlCount"] - tmpTaskBlValue["blIsCoveredCount"]
                if standardDataDict[tmpTaskBlKey]["businessLineCount"] != 0:
                    tmpTaskBlValue["blCoverage"] = '%.2f' % (tmpTaskBlValue["blIsCoveredCount"] / standardDataDict[tmpTaskBlKey]["businessLineCount"] * 100)
                for tmpTaskMdKey,tmpTaskMdValue in tmpTaskBlValue["blContainsMd"].items():

                    tmpTaskMdValue["notStandardCount"] = tmpTaskMdValue["mdCount"] - tmpTaskMdValue["mdIsCoveredCount"]
                    if tmpTaskMdKey in standardDataDict[tmpTaskBlKey]["moduleDict"].keys():
                        tmpTaskMdValue["standardMdCount"] = standardDataDict[tmpTaskBlKey]["moduleDict"][tmpTaskMdKey]["moduleCount"]
                        tmpTaskMdValue["mdNotCoveredCount"] = tmpTaskMdValue["standardMdCount"] - tmpTaskMdValue["mdIsCoveredCount"]
                        if standardDataDict[tmpTaskBlKey]["moduleDict"][tmpTaskMdKey]["moduleCount"] != 0:
                            tmpTaskMdValue["mdCoverage"] = '%.2f' % (tmpTaskMdValue["mdIsCoveredCount"] / standardDataDict[tmpTaskBlKey]["moduleDict"][tmpTaskMdKey]["moduleCount"] * 100)

    t77 = time.time()
    print("[计算任务覆盖率]t77-t76:%f" % (t77 - t76))

    context["taskDict"] = taskDict
    response = render(request, "InterfaceTest/src_file_analyze/SubPages/src_task_file_cover_sub_page.html", context)
    t8= time.time()
    print("[render]t8-t77:%f" % (t8-t77))

    print("[所有计算时间]t8-t7:%f" % (t8-t7))

    return response