def copy_plan(data: PlanHandleRequest): """ 复制测试计划 :param data: :return: """ plan: PlanModel = service.find_plan_by_id(data.plan_id) if data.version_id is None and plan.parent_id is not None: parent_plan = service.find_plan_by_id(plan.parent_id) data.version_id = parent_plan.version_id version = service.find_version_by_id(data.version_id) if version is None: return make_error_response("版本错误") def set_id(p: PlanModel, parent_id): p.plan_id = random_id() p.version_id = version.version_id p.parent_id = parent_id for item in p.children: set_id(item, p.plan_id) set_id(plan, plan.parent_id) plan.name = data.name plan.version_id = version.version_id service.update_plan(plan) return make_no_data_response("创建成功")
def start_error_test_by_task(data: TaskRequest): """ 运行本次任务中的错误用例 :param data: selected_node记录了错误的用例 :return: """ if data.selected_node is None or len(data.selected_node) == 0: return make_error_response("执行错误:没有找到错误的页面") task = service.find_task_by_task_id(data.group_id, data.task_id) plan = service.find_plan_by_id(task.plan_id) version = service.find_version_by_id(plan.version_id) page_data = service.find_selected_pages_by_selected_node( version, data.selected_node) if len(page_data) == 0: return make_error_response('执行错误:没有找到错误的页面') for page_data_item in page_data: method_data_list = [] for d in page_data_item['method_data']: for method_data in d['data']: method_data_list.append(method_data) plan_data_cover_page_data(plan.data, page_data_item['data'], method_data_list) task.time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) task.group_id = random_id() task.task_id = random_id() task.page_data = page_data task.name = task.name + ":只执行错误用例" task.session_id = session_id task.wait() service.update_task(task) return make_no_data_response()
def del_plan(data: PlanHandleRequest): """ 删除测试计划 :param data: :return: """ plan = service.find_plan_by_id(data.plan_id) service.del_plan(plan) if plan.parent_id is None: version = service.find_version_by_id(data.version_id, include_del=True) if version is not None and version.is_del: service.del_pages_versions(version) service.del_pages_info(version) return make_no_data_response("删除成功")
def start_test_by_task(data: TaskRequest): """ 通过一个任务启动测试,一般用于回测 :param data: :return: """ task = service.find_task_by_task_id(data.group_id, data.task_id) if task is None: return make_error_response('该任务已不存在') plan = service.find_plan_by_id(task.plan_id) if plan is None: return make_error_response('该计划已不存在') task.group_id = random_id() task.task_id = random_id() task.time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) task.session_id = session_id # 更新为本次的session task.wait() service.update_task(task) return make_no_data_response()
def del_plan_data(data: PlanHandleRequest): """ 删除测试计划的页面数据 :param data: :return: """ plan = service.find_plan_by_id(data.plan_id) if plan is None: return make_error_response("没有找到该计划") pending_del_id = [item for item in map(lambda item: item.id, data.data)] new_data = [ item for item in filter(lambda item: item.id not in pending_del_id, plan.data) ] plan.data = new_data service.update_plan(plan) return make_no_data_response()
def save_plan_data(data: PlanHandleRequest): """ 保存测试计划中的页面数据, :param data: :return: """ names = [item for item in map(lambda item: item.name, data.data)] set_name = set(names) if len(set_name) != len(names): return make_error_response("不可以重复添加变量名") plan = service.find_plan_by_id(data.plan_id) if plan is None: return make_error_response("没有找到该计划") plan.data = data.data service.update_plan(plan) return make_no_data_response()
def update_selected_page_node(data: PlanHandleRequest): """ 更新测试计划中选择的测试页面 :param data: :return: """ names = [item for item in map(lambda item: item.name, data.data)] set_name = set(names) if len(set_name) != len(names): return make_error_response("不可以重复添加变量名") plan = service.find_plan_by_id(data.plan_id) if plan is None: return make_error_response("没有找到该计划") plan.selected_page_node = data.selected_page_node service.update_plan(plan) return make_no_data_response()
def add_plan(data: PlanHandleRequest): """ 添加测试计划 :param data: :return: """ version = service.find_version_by_id(data.version_id) if version is None: return make_error_response("版本错误") plan = PlanModel.create(data.name, data.version_id, data.parent_id) if data.parent_id is not None: parent_plan = service.find_plan_by_id(data.parent_id) if parent_plan is not None: plan.selected_page_node = parent_plan.selected_page_node for plan_data in parent_plan.data: plan.data.append(plan_data.copy()) service.update_plan(plan) return make_no_data_response("创建成功")