Пример #1
0
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("创建成功")
Пример #2
0
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()
Пример #3
0
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()
Пример #4
0
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()
Пример #5
0
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("创建成功")