Ejemplo n.º 1
0
def testCaseAddPage(request, context):
    langDict = getLangTextDict(request)

    context["page"] = 1
    context["option"] = "add"
    context["dubbo_addHTTPTestCase"] = "current-page"
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    if not isRelease:
        context["env"] = "test"
    # 文本
    text = {}
    text["pageTitle"] = langDict["dubbo"]["dubboTestCasePageHeadings_%s" %
                                          context["option"]]
    text["subPageTitle"] = langDict["dubbo"]["dubboTestCaseSubPageTitle_%s" %
                                             context["option"]]
    context["text"] = text

    # 页面所需参数
    context["loginName"] = request.session.get("loginName")
    context.update(getConfigs(request))

    context["debugBtnCount"] = commonWebConfig.debugBtnCount

    # 调试按钮
    getDebugBtnList = ConfigServiceForDubbo.getDebugBtn(request)
    context.update(getDebugBtnList)

    context["title"] = "添加DUBBO业务流"
    return render(request, "dubbo/testcase/testCase.html", context)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def http_interfaceCheck(request):
    request.session['groupLevel1'] = groupLevel1
    request.session['groupLevel2'] = groupLevel2
    request.session['isReleaseEnv'] = isRelease

    langDict = getLangTextDict(request)
    context = {}
    if not isRelease:
        context["env"] = "test"
    context["mockinterfaceCheck"] = "current-page"
    context["userName"] = request.session.get("userName")
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    # 文本
    text = {}
    text["pageTitle"] = "MOCK接口查看"
    context["text"] = text
    context["page"] = 1
    # context["lang"] = getLangTextDict(request)
    context["uri"] = UriService.getUri(request, "HTTP")

    addUserLog(request, "MOCK管理->查看MOCK->页面展示->成功", "PASS")
    context["title"] = "HTTP MOCK"
    return render(request, "mock_server/http/HTTP_interface_check.html",
                  context)
Ejemplo n.º 4
0
    def getConfigs(request):
        context = {}
        context["businessLine"] = BusinessService.getBusiness()
        context["modules"] = ModulesService.getModules()
        context["source"] = SourceService.getAllSource()
        context["uri"] = UriServiceForDubbo.getUri(request)

        return context
Ejemplo n.º 5
0
def getBusinessLineAndModuleRelation(request):
    businessLineListData = dbModelListToListDict(BusinessService.getAllBusinessLine())
    resultDict = {}
    for blIndex in businessLineListData:
        resultDict[blIndex["id"]] = []
        dataList = dbModelListToListDict(TbBusinessLineModuleRelation.objects.filter(businessLineId__bussinessLineName=blIndex["bussinessLineName"],businessLineId__state=1).order_by("level"))
        for index in dataList:
            resultDict[blIndex["id"]].append(dbModelToDict(TbModules.objects.get(id=index["moduleId_id"])))
    return HttpResponse(ApiReturn(body=resultDict).toJson())
Ejemplo n.º 6
0
def runContrackTask(request):
    mockId = request.GET.get("mockId")
    httpConfKey = request.GET.get("httpConfKey")
    if(mockId):
        mockInfo = MockHttpService.getInterfaceByMockId(mockId)
        if mockInfo:
            if mockInfo.interfaceIds.strip(",").strip() == "":
                return HttpResponse(ApiReturn(code=ApiReturn.CODE_ERROR, message="没有发现契约接口信息!", body=mockId + httpConfKey).toJson())
        else:
            return HttpResponse(ApiReturn(code=ApiReturn.CODE_ERROR, message="没有发现mock信息!", body=mockId + httpConfKey).toJson())
    else:
        return HttpResponse(ApiReturn(code=ApiReturn.CODE_ERROR, message="必须有mockId参数!", body=mockId + httpConfKey).toJson())

    if httpConfKey:
        pass
    else:
        return HttpResponse(ApiReturn(code=ApiReturn.CODE_ERROR, message="必须有httpConfKey参数!", body=mockId + httpConfKey).toJson())

    taskExc = TbTaskExecute()
    taskExc.taskId = "CONTRACT_TASK_%s" % mockId
    taskExc.title = "契约测试:%s" % mockInfo.title
    taskExc.taskdesc = taskExc.title
    taskExc.protocol = "HTTP"
    taskExc.businessLineGroup = "['%s']" % BusinessService.getBusinessLineNameById(mockInfo.businessLineId)
    taskExc.modulesGroup = "['%s']" % ModulesService.getModuleNameById(mockInfo.moduleId)
    taskExc.interfaceCount = len(mockInfo.interfaceIds.strip(",").split(","))
    taskExc.taskInterfaces = mockInfo.interfaceIds.strip(",")
    taskExc.caseCount = 0
    taskExc.interfaceNum = taskExc.interfaceCount

    taskExc.httpConfKey = TbConfigHttp.objects.filter(httpConfKey=httpConfKey.strip()).get()
    taskExc.execComments = "执行契约测试任务"
    taskExc.testResultMsg = ""
    taskExc.testReportUrl = ""

    taskExc.addBy = TbUser.objects.filter(loginName = request.session.get("loginName")).get()
    taskExc.execBy = TbUser.objects.filter(loginName = request.session.get("loginName")).get()
    taskExc.save(force_insert=True)

    addDataResult = dbModelToDict(taskExc)
    # 将任务执行的信息写入缓存,任务执行的前缀为 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"]))
    bodyDict = {
        "taskExecuteId":taskExc.id,
        "taskId":taskExc.taskId
    }
    return HttpResponse(ApiReturn(code=ApiReturn.CODE_OK,message="ok",body=bodyDict).toJson())
Ejemplo n.º 7
0
def srcFileCoverCheck(request):
    langDict = getLangTextDict(request)
    context = {}

    context["srcFileCoverCheck"] = "current-page"
    context["userName"] = request.session.get("userName")
    if not isRelease:
        context["env"] = "test"

    # 文本
    text = {}
    text["pageTitle"] = langDict["web"]["srcFileAnalyzePageTitle"]
    text["subPageTitle"] = langDict["web"]["httpUserCenterGlobalVarsSubPageTitle"]
    context["text"] = text
    context["checkBusinessLine"] = dbModelListToListDict(BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(ModulesService.getAllModules())

    context["page"] = 1
    return render(request, "InterfaceTest/src_file_analyze/src_file_cover.html", context)
Ejemplo n.º 8
0
def http_testCaseStepCheck(request):
    context = {}

    context["testCaseStepCheck"] = "current-page"
    context["userName"] = request.session.get("userName")
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    if not isRelease:
        context["env"] = "test"
    #文本
    text = {}
    text["pageTitle"] = "HTTP用例步骤查看"
    context["text"] = text

    context["page"] = 1
    return render(request,
                  "InterfaceTest/HTTPTestCase/HTTP_testCaseStep_check.html",
                  context)
Ejemplo n.º 9
0
def taskResultCheck(request):
    langDict = getLangTextDict(request)

    context = {}
    if not isRelease:
        context["env"] = "test"
    context["taskExecuteResult"] = "current-page"
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    context["httpConf"] = HttpConfService.queryHttpConfSort(request)
    # 文本
    text = {}
    text["pageTitle"] = langDict["web"]["httpTaskCheckPageHeadings_check"]
    context["text"] = text

    context["page"] = 1
    return render(request, "InterfaceTest/HTTPTask/HTTP_task_ExecResult.html",
                  context)
Ejemplo n.º 10
0
def taskAdd(request, context):
    langDict = getLangTextDict(request)
    context["interfacePage"] = 1
    context["testCasePage"] = 1
    context["option"] = "add"
    if not isRelease:
        context["env"] = "test"
    context["taskAdd"] = "current-page"
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    context.update(getServiceConf(request))
    text = {}
    text["pageTitle"] = langDict["web"]["httpTaskPageHeadings_%s" %
                                        context["option"]]
    text["subPageTitle"] = langDict["web"]["httpTaskSubPageTitle_%s" %
                                           context["option"]]
    context["text"] = text
    # return request.session.get("loginName"),request, "InterfaceTest/HTTPTask/HTTP_taskAdd.html", context
    return render(request, "InterfaceTest/HTTPTask/HTTP_taskAdd.html", context)
Ejemplo n.º 11
0
def dubbo_testCaseCheck(request):
    langDict = getLangTextDict(request)
    context = {}

    context["dubbo_testCaseCheck"] = "current-page"
    context["userName"] = request.session.get("userName")
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    if not isRelease:
        context["env"] = "test"
    # 文本
    text = {}
    text["pageTitle"] = langDict["dubbo"]["dubboTestCasePageHeadings_check"]
    context["text"] = text

    context["page"] = 1

    # context["lang"] = getLangTextDict(request)
    context["title"] = "DUBBO业务流"
    return render(request, "dubbo/testcase/testCase_check.html", context)
Ejemplo n.º 12
0
def srcFileList(request):

    page = request.POST.get("page")
    if isInt(page):
        page = int(page)
    else:
        return HttpResponse("<script>alert('请验证页数参数');</script>")
    checkArr = json.loads(parse.unquote(request.POST.get("queryArr")))
    orderBy = request.POST.get("orderBy")
    if isSqlInjectable(orderBy):
        return HttpResponse("<script>alert('查询条件非法');</script>")

    if VersionService.isCurrentVersion(request):
        tbName = "tb_standard_interface"
        versionCondition = ""
    else:
        tbName = "tb_version_standard_interface"
        versionCondition = "and g.versionName='%s'" % request.session.get(
            "version")

    execSql = "SELECT g.*,m.moduleName,b.bussinessLineName FROM %s g LEFT JOIN tb_modules m on g.moduleId = m.id LEFT JOIN tb_business_line b on g.businessLineId = b.id WHERE g.state=1 %s" % (
        tbName, versionCondition)
    checkList = []
    for key in checkArr:
        if checkArr[key] == "":
            continue
        elif key == "businessLine":
            checkList.append("%%%s%%" % checkArr[key])
            execSql += """ and b.bussinessLineName LIKE %s """
            continue
        elif key == "module":
            checkList.append("%%%s%%" % checkArr[key])
            execSql += """ and m.moduleName LIKE %s """
            continue
        elif key == "fileRealPath":
            checkList.append("%%%s%%" % checkArr[key])
            execSql += """ and g.fileName LIKE %s """
            continue
        elif key == "interfaceUrl":
            checkList.append("%%%s%%" % checkArr[key])
            execSql += """ and g.interfaceUrl LIKE %s """
            continue
        elif key == "apiStatus":
            statusDict = {"有效": "1", "废弃": "0", "未发现注释": "3", "注释不合法": "4"}
            statusValue = statusDict[checkArr[key]]
            checkList.append("%s" % statusValue)
            execSql += """ and g.apiStatus = %s """
            continue
        checkList.append("%%%s%%" % checkArr[key])
        execSql += """ and g.%s """ % key
        execSql += """ LIKE %s"""
    execSql += """ ORDER BY %s""" % orderBy
    print(execSql)
    context = pagination(sqlStr=execSql,
                         attrList=checkList,
                         page=page,
                         pageNum=commonWebConfig.standardInterfacePageNum)
    context["checkBusinessLine"] = dbModelListToListDict(
        BusinessService.getAllBusinessLine())
    context["checkModules"] = dbModelListToListDict(
        ModulesService.getAllModules())
    response = render(
        request,
        "InterfaceTest/src_file_analyze/SubPages/src_file_sub_page.html",
        context)
    return response
Ejemplo n.º 13
0
    def taskDataToDict(request, taskData):
        taskInterfaceBusinessLineArr = []
        taskInterfaceModulesArr = []
        taskInterfaceSourceArr = []
        if taskData["taskInterfaces"] != "":
            # 去重,切成数组遍历获取业务线名称
            taskInterfaceList = list(set(
                taskData["taskInterfaces"].split(",")))
            taskInterfaceListPartSql = ''
            for i in range(0, len(taskInterfaceList)):
                if i == 0:
                    taskInterfaceListPartSql = "interfaceId = '%s'" % taskInterfaceList[
                        i]
                    continue
                taskInterfaceListPartSql += " or interfaceId = '%s'" % taskInterfaceList[
                    i]
            if VersionService.isCurrentVersion(request):
                taskInterfaceBusinessLineArr = BusinessService.getInterfaceListBusinessId(
                    taskInterfaceListPartSql)
                taskInterfaceModulesArr = ModulesService.getInterfaceListModulesId(
                    taskInterfaceListPartSql)
                taskInterfaceSourceArr = SourceService.getInterfaceListSourcesId(
                    taskInterfaceListPartSql)
            else:
                taskInterfaceBusinessLineArr = BusinessService.getVersionInterfaceListBusinessId(
                    taskInterfaceListPartSql,
                    VersionService.getVersionName(request))
                taskInterfaceModulesArr = ModulesService.getVersionInterfaceListModulesId(
                    taskInterfaceListPartSql,
                    VersionService.getVersionName(request))
                taskInterfaceSourceArr = SourceService.getVersionInterfaceListSourcesId(
                    taskInterfaceListPartSql,
                    VersionService.getVersionName(request))

        taskTestCaseBusinessLineArr = []
        taskTestCaseModulesArr = []
        taskTestCaseSourceArr = []
        if taskData["taskTestcases"] != "":
            # 去重,切成数组遍历获取业务线名称
            taskTestCaseList = list(set(taskData["taskTestcases"].split(",")))
            taskTestCasePartSql = ""
            for i in range(0, len(taskTestCaseList)):
                if i == 0:
                    taskTestCasePartSql = "caseId = '%s'" % taskTestCaseList[i]
                    continue
                taskTestCasePartSql += " or caseId = '%s'" % taskTestCaseList[i]

            if VersionService.isCurrentVersion(request):
                taskTestCaseBusinessLineArr = BusinessService.getTestCaseListBusinessId(
                    taskTestCasePartSql)
                taskTestCaseModulesArr = ModulesService.getTestCaseListModulesId(
                    taskTestCasePartSql)
                taskTestCaseSourceArr = SourceService.getTestCaseListSourcesId(
                    taskTestCasePartSql)
            else:
                taskTestCaseBusinessLineArr = BusinessService.getVersionTestCaseListBusinessId(
                    taskTestCasePartSql,
                    VersionService.getVersionName(request))
                taskTestCaseModulesArr = ModulesService.getVersionTestCaseListModulesId(
                    taskTestCasePartSql,
                    VersionService.getVersionName(request))
                taskTestCaseSourceArr = SourceService.getVersionTestCaseListSourcesId(
                    taskTestCasePartSql,
                    VersionService.getVersionName(request))

        businessLineGroupArr = taskInterfaceBusinessLineArr + taskTestCaseBusinessLineArr
        businessLineGroup = []
        for i in range(0, len(businessLineGroupArr)):
            businessLineGroup.append(
                businessLineGroupArr[i]["bussinessLineName"])
        taskData["businessLineGroup"] = list(set(businessLineGroup))

        modulesGroupArr = taskInterfaceModulesArr + taskTestCaseModulesArr
        modulesGroup = []
        for i in range(0, len(modulesGroupArr)):
            modulesGroup.append(modulesGroupArr[i]["moduleName"])
        taskData["modulesGroup"] = list(set(modulesGroup))
        taskData["protocol"] = "HTTP"
        taskData["modBy"] = request.session.get("loginName")
        taskData["modByName"] = request.session.get("userName")

        sourcesGroupArr = taskInterfaceSourceArr + taskTestCaseSourceArr
        sourceGroup = []
        for i in range(0, len(sourcesGroupArr)):
            sourceGroup.append(sourcesGroupArr[i]["sourceName"])
        taskData["sourceGroup"] = list(set(sourceGroup))
        return taskData