def getGlobalTextForVarKey(request): textKey = request.GET.get("textKey", None) token = request.GET.get("token", None) if textKey == None: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数textKey 不能为空").toJson()) if token == None: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数token 不能为空").toJson()) getUser = TbUser.objects.filter(token=token, state=1) if len(getUser) == 0: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数token 查询用户错误").toJson()) getText = TbGlobalText.objects.filter(textKey=textKey, state=1) if len(getText) == 0: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数varKey 查询全局变量错误").toJson()) serviceConfList = ServiceConfService.getServiceConf() textData = getText.last().textValue retVar = {} if "[CONF=common]" in textData: retVar["common"] = substr(textData, "[CONF=common]", "[ENDCONF]") for serviceIndex in serviceConfList: if "[CONF=%s]" % serviceIndex["serviceConfKey"] not in textData: continue retVar[serviceIndex["serviceConfKey"]] = substr( textData, "[CONF=%s]" % serviceIndex["serviceConfKey"], "[ENDCONF]") return HttpResponse(ApiReturn(ApiReturn.CODE_OK, body=retVar).toJson())
def userHttpConfCheck(request): langDict = getLangTextDict(request) context = {} context["httpUserCenterUserHttpConfPage"] = "current-page" context["userName"] = request.session.get("userName") if not isRelease: context["env"] = "test" # 文本 text = {} text["pageTitle"] = langDict["web"]["httpUserCenterUserHttpConfPageTitle"] text["subPageTitle"] = langDict["web"][ "httpUserCenterUserHttpConfSubPageTitle"] context["text"] = text serviceConf = ServiceConfService.getServiceConf() context["services"] = serviceConf # context["uriServices"] = UriService.getUri(request) # context["dubboServices"] = dbModelListToListDict(TbConfigUri.objects.filter(state=1,protocol="DUBBO").order_by("level")) context["envConfList"] = HttpConfService.getAllHttpConf(request) # context["uri"] = UriService.getUri(request, "ALL") context["page"] = 1 context["title"] = "环境配置" return render(request, "InterfaceTest/user_center/user_http_conf.html", context)
def setGlobalVarForVarKey(request): varKey = request.POST.get("varKey", None) token = request.POST.get("token", None) varValue = request.POST.get("varValue", None) if varKey == None: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数varKey 不能为空").toJson()) if token == None: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数token 不能为空").toJson()) getUser = TbUser.objects.filter(token=token, state=1) if len(getUser) == 0: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数token 查询用户错误").toJson()) getVar = TbGlobalVars.objects.filter(varKey=varKey, state=1) if len(getVar) == 0: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数varKey 查询全局变量错误").toJson()) if type(varValue) == type(""): if not isJson(varValue): return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数varValue不是JSON格式").toJson()) varDict = json.loads(varValue) else: try: varDict = eval(varValue) except: return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, message="参数varValue不是JSON格式").toJson()) serviceConfList = ServiceConfService.getServiceConf() serviceList = [] for serviceIndex in serviceConfList: serviceList.append(serviceIndex["serviceConfKey"]) varText = "" for index in varDict: if index != "common" and index not in serviceList: print(index) return HttpResponse( ApiReturn(ApiReturn.CODE_ERROR, "varValue中存在Key不为HTTPConfKey").toJson()) varText += "[CONF=%s]%s[ENDCONF]" % (index, varDict[index]) varData = getVar.last() varData.varValue = varText varData.modBy = getUser.last().loginName varData.save() return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())
def getInterfaceDataForId(request): langDict = getLangTextDict(request) serviceConf = ServiceConfService.queryServiceConfSort(request) # 根据版本判断应该从哪个表里取数据 王吉亮添加于20180224 if VersionService.isCurrentVersion(request): getDBData = MockHttpService.getInterfaceForIdToDict(request.GET.get("id")) interfaceIdList = getDBData['interfaceIds'].strip(",").split(',') interfaceList = [] for tmpInterfaceId in interfaceIdList: if tmpInterfaceId.strip() != "": interfaceList.append(dbModelToDict(HTTP_interfaceService.getInterfaceByInterfaceId(tmpInterfaceId.strip()))) getDBData['interfaceList'] = interfaceList else: getDBData = MockHttpService.getVersionInterfaceForIdToDict(request.GET.get("id"),request.session.get("version")) return HttpResponse(ApiReturn(ApiReturn.CODE_OK, langDict["web"]["httpInterfaceSuccess"], json.dumps(getDBData)).toJson())
def operationInterface(request, context): langDict = getLangTextDict(request) context["id"] = request.GET.get("id") context["option"] = request.GET.get("option") context["addHTTPInterface"] = "current-page" context["title"] = "HTTP MOCK-" + request.GET.get("id") if not isRelease: context["env"] = "test" try: if VersionService.isCurrentVersion(request): context["dataAddBy"] = MockHttpService.getInterfaceForId( request.GET.get("id")).addBy else: context["dataAddBy"] = MockHttpService.getVersionInterfaceForId( request.GET.get("id")).addBy except Exception as e: return render(request, "permission/page_404.html") # 文本 text = {} try: text["pageTitle"] = "MOCK接口" if context["option"] == "select": text["subPageTitle"] = "查看MOCK接口" elif context["option"] == "edit": text["subPageTitle"] = "编辑MOCK接口" elif context["option"] == "copy": text["subPageTitle"] = "添加MOCK接口" except Exception as e: return HttpResponse("参数错误 %s" % e) context["text"] = text context.update(getConfigs(request)) context.update(getServiceConf(request)) context["debugBtnCount"] = commonWebConfig.debugBtnCount getDebugBtnList = getDebugBtn(request) context.update(getDebugBtnList) context["serviceJson"] = json.dumps( ServiceConfService.queryServiceConfSort(request)) context["importStr"] = getPythonThirdLib() return render(request, "mock_server/http/HTTP_interface.html", context)
def operationTestCase(request, context): langDict = getLangTextDict(request) context["id"] = request.GET.get("id") context["option"] = request.GET.get("option") context["page"] = 1 context["dubbo_addHTTPTestCase"] = "current-page" if not isRelease: context["env"] = "test" try: if VersionService.isCurrentVersion(request): context["dataAddBy"] = DubboTestcaseService.getTestCaseForId( request.GET.get("id")).addBy.loginName else: context[ "dataAddBy"] = HTTP_test_caseService.getVersionTestCaseForId( request.GET.get("id")).addBy.loginName except Exception as e: return HttpResponse("参数id错误 %s" % e) # 文本 text = {} try: text["pageTitle"] = langDict["dubbo"]["dubboTestCasePageHeadings_%s" % context["option"]] text["subPageTitle"] = langDict["dubbo"]["dubboTestCasePageHeadings_%s" % context["option"]] except Exception as e: return HttpResponse("参数错误 %s" % e) context["text"] = text context.update(ConfigServiceForDubbo.getConfigs(request)) context.update(getServiceConf(request)) context["debugBtnCount"] = commonWebConfig.debugBtnCount getDebugBtnList = ConfigServiceForDubbo.getDebugBtn(request) context.update(getDebugBtnList) context["serviceJson"] = json.dumps( ServiceConfService.queryServiceConfSort(request)) context["title"] = "DUBBO业务流-" + request.GET.get("id") return render(request, "dubbo/testcase/testCase.html", context)
def getTextConf(request): id = request.GET.get("id") if VersionService.isCurrentVersion(request): varData = dbModelToDict(global_textService.getText(id)) else: varData = dbModelToDict(global_textService.getVersionText(id)) serviceConf = ServiceConfService.queryServiceConfSort(request) varData["serviceConf"] = {} varData["serviceConf"]["common"] = substr(varData["textValue"], "[CONF=common]", "[ENDCONF]") for i in range(0, len(serviceConf)): if serviceConf[i]["serviceConfKey"] not in varData["textValue"]: varData["serviceConf"]["%s" % serviceConf[i]["serviceConfKey"]] = "" continue varData["serviceConf"]["%s" % serviceConf[i]["serviceConfKey"]] = substr( varData["textValue"], "[CONF=%s]" % serviceConf[i]["serviceConfKey"], "[ENDCONF]") return HttpResponse(ApiReturn(body=varData).toJson())
def getServiceConf(request): context = {} serviceConf = ServiceConfService.queryServiceConfSort(request) context["serviceCount"] = len(serviceConf) serviceIncludeHTTPConf = [] # serviceList = [] # 显示前置和后置变量的title for i in range(0, len(serviceConf)): # serviceList.append(serviceConf[i]["serviceConfKey"]) serviceIncludeHTTPConf.append( HttpConfService.getServiceIncludHttpConf( serviceConf[i]["serviceConfKey"])) httpConfStrList = "" for j in range(0, len(serviceIncludeHTTPConf[i])): if j == 0: httpConfStrList = "包含的环境:%s" % serviceIncludeHTTPConf[i][j][ "alias"] continue httpConfStrList = "%s,%s" % (httpConfStrList, serviceIncludeHTTPConf[i][j]["alias"]) serviceConf[i]["serviceIncludeHTTPConf"] = httpConfStrList context["service"] = serviceConf return 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())
def getServiceConf(request): serviceConf = ServiceConfService.queryServiceConfSort(request) return HttpResponse(json.dumps(serviceConf))