def get_result_detail_list(data): result_id = data["result_id"] body_list = [] result_detail_list = ResultDetail.objects.all().filter(result_id=result_id) for result_datail in result_detail_list: a = jsontool.class_to_dict(result_datail) a["input_data"] = eval(a["input_data"]) a["out_data"] = eval(a["out_data"]) b = jsontool.class_to_dict(Case.objects.all().get(case_id=a["case_id"])) del (b['input_data']) c = jsontool.class_to_dict(Api.objects.all().get(api_id=a["api_id"])) if b["check_id"] != 0: checker = jsontool.class_to_dict(CheckModel.objects.all().get(check_id=b["check_id"])) else: checker = { "check_name":"", "check_desc":"默认", "check_code":"", } b = dict(b, **checker) var = dict(a, **b) var = dict(var, **c) del (var['_state']) if result_datail.is_pass !=2: var["out_data"]["response_data"]["body"] = json.dumps(var["out_data"]["response_data"]["body"]) # var["out_data"]["response_data"]["header"] = str(var["out_data"]["response_data"]["header"]).replace("\'", "\"") body_list.append(var) body_list.sort(key=lambda api: api["api_id"], reverse=False) return { "code": 1, "msg": "返回成功", "data": body_list }
def get_result_detail(data): result_detail_id = data["result_detail_id"] result_detail = ResultDetail.objects.all().get(result_detail_id=result_detail_id) a = jsontool.class_to_dict(result_detail) a["input_data"] = jsontool.str_to_json(a["input_data"]) a["out_data"] = jsontool.str_to_json(a["out_data"]) b = jsontool.class_to_dict(Case.objects.all().get(case_id=a["case_id"])) del (b['input_data']) c = jsontool.class_to_dict(Api.objects.all().get(api_id=a["api_id"])) if b["check_id"] != 0: checker = jsontool.class_to_dict(CheckModel.objects.all().get(check_id=b["check_id"])) else: checker = { "check_name": "", "check_desc": "默认", "check_code": "", } b = dict(b, **checker) var = dict(a, **b) var = dict(var, **c) del (var['_state']) var["input_data"]["body"] = str(var["input_data"]["body"]).replace("\'", "\"") var["input_data"]["url"] = str(var["input_data"]["url"]).replace("\'", "\"") var["out_data"]["response_data"]["body"] = str(var["out_data"]["response_data"]["body"]).replace("\'", "\"") var["out_data"]["response_data"]["header"] = str(var["out_data"]["response_data"]["header"]).replace("\'", "\"") return { "code": 1, "msg": "返回成功", "data": var }
def get_result_list(data): pro_id = data["pro_id"] body = [] test = Result.objects.all().filter(pro_id=pro_id) for a in list(test): a = jsontool.class_to_dict(a) b = jsontool.class_to_dict(Suite.objects.all().get(suite_id=a["suite_id"])) var = dict(a, **b) del (var['_state']) body.append(var) body.reverse() return { "code": 1, "msg": "获取成功", "data": body }
def get_env_list(data): """ 获取环境列表 :param data: :return: """ try: pro_id = data['pro_id'] body = [] test = Env.objects.all().filter(pro_id=pro_id) for a in list(test): a = jsontool.class_to_dict(a) del (a['_state']) body.append(a) return { "code": 1, "msg": "获取环境列表成功", "data": body } except Exception as e: print(e) return { "code": 0, "msg": "参数错误" }
def get_func_list(data): pro_id = data["pro_id"] body = [] test = Functions.objects.all().filter(pro_id=pro_id) for a in list(test): a = jsontool.class_to_dict(a) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body}
def get_suite_case_list(data): suite_id = data["suite_id"] body = [] test = CaseSuite.objects.all().filter(suite_id=suite_id) for a in list(test): a = jsontool.class_to_dict(Case.objects.all().get(case_id=a.case_id)) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body}
def get_module_case_list(data): module_id = data["module_id"] body = [] test = Case.objects.all().filter(module_id=module_id) for a in list(test): a = jsontool.class_to_dict(a) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body}
def get_pro_case_list(data): pro_id = data["pro_id"] body = [] test = list( set(CaseSuite.objects.all().filter(pro_id=pro_id).values_list( "case_id", flat=True))) for a in test: a = jsontool.class_to_dict(Case.objects.all().get(case_id=a)) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body}
def get_api_case_list(data): api_id = data["api_id"] body = [] test = Case.objects.all().filter(api_id=api_id) for a in test: a = jsontool.class_to_dict(a) suite_list = list(CaseSuite.objects.all().filter( case_id=a["case_id"]).values_list("suite_id", flat=True)) del (a['_state']) a["suite_list"] = suite_list body.append(a) return {"code": 1, "msg": "获取成功", "data": body}
def get_env_varList(data): """ 获取该环境下的变量列表 :param data: :return: """ env_id = data["env_id"] body = [] test = VarValue.objects.all().filter(env_id=env_id) for a in list(test): a = jsontool.class_to_dict(a) var_info = jsontool.class_to_dict(Vars.objects.all().get(var_id=a["var_id"])) var = dict(a, **var_info) del (var['id']) del (var['_state']) body.append(var) return { "code": 1, "msg": "返回成功", "data": body }
def get_dapi_list(data): """ 获取项目下的套件列表 :return: """ pro_id = data["pro_id"] body = [] test = DepndApi.objects.all().filter(pro_id=pro_id) for a in list(test): a = jsontool.class_to_dict(a) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body}
def get_var_list(data): """ 获取变量信息列表 :param data: :return: """ pro_id = data["pro_id"] body = [] var_list_ob = Vars.objects.all().filter(pro_id=pro_id) for var_ob in var_list_ob: a = jsontool.class_to_dict(var_ob) del (a['_state']) body.append(a) return {"code": 1, "msg": "返回成功", "data": body}
def get_var_of_env(data): """ 获取变量在不同环境的所有值 :param data: :return: """ var_id = data["var_id"] body_list = [] var_value_list = VarValue.objects.all().filter(var_id=var_id) var_info = jsontool.class_to_dict(Vars.objects.all().get(var_id=var_id)) del (var_info['_state']) for var_value in var_value_list: a = jsontool.class_to_dict(var_value) b = jsontool.class_to_dict(Env.objects.all().get(env_id=a["env_id"])) var = dict(a, **b) del (var['_state']) del (var['id']) del (var['pro_id']) del (var['var_id']) body_list.append(var) body = {"value": body_list} body = dict(body, **var_info) return {"code": 1, "msg": "返回成功", "data": body}
def get_pro_list(): """ 获取所有的项目 :return: 所有的项目,类型为列表 """ try: body = [] test = Project.objects.all() for a in list(test): a = jsontool.class_to_dict(a) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body} except Exception as e: print(e) return { "code": 0, "msg": "获取失败", }
def get_plan_list(data): pro_id = data["pro_id"] status = data["status"] body = [] now_time = int(time.time()) if status == 0: # 全部 plan_list = RunPlan.objects.all().filter(pro_id=pro_id) elif status == 1: # 进行中 plan_list1 = list(RunPlan.objects.all().filter(end_time__gte=now_time, plan_type=1, pro_id=pro_id)) plan_list2 = list(RunPlan.objects.all().filter( start_time__gte=now_time, plan_type=2, pro_id=pro_id)) plan_list = plan_list1 + plan_list2 elif status == 2: # 已完成 plan_list = list(RunPlan.objects.all().filter(end_time__lte=now_time, pro_id=pro_id)) for a in list(plan_list): a = jsontool.class_to_dict(a) del (a['_state']) body.append(a) return {"code": 1, "msg": "获取成功", "data": body}