Ejemplo n.º 1
0
def use_case_copy_interface():
    """
    复制用例时同时复制用例接口和参数值
    :return:
    """
    param_dict = request.get_json(force=True)
    interface_list = param_dict.get('interface_list')
    if not isinstance(interface_list, list):
        interface_list = [interface_list]
    add_param_dict = {
        "use_case_id": param_dict.get("use_case_id"),
        "interface_id": ""
    }
    for interface in interface_list:
        if not interface['interface_id']:
            continue
        add_param_dict["interface_id"] = interface['interface_id']
        relation_id = Case_API.add_relation(**add_param_dict)
        param_list = interface['param_list']
        for para in param_list:
            parameter_value = para['parameter_value']
            parameter_name = para['parameter_name']
            Case_API.add_case_parameter_relation(
                relation_id=relation_id,
                parameter_name=parameter_name,
                parameter_value=parameter_value)
    return jsonify({'success': True})
Ejemplo n.º 2
0
def add_relation():
    """
    功能描述: 将某个interface与某个use_case关联
    1. 关联use_case与interface
    2. 查找interface内parameter信息, 用空值为每个参数在relation下生成记录
    :return:
    """
    param_dict = request.get_json()
    interface_list = param_dict.get('interface_id')
    if not isinstance(interface_list, list):
        interface_list = [interface_list]
    add_param_dict = {"use_case_id": param_dict.get("use_case_id"), "interface_id": ""}
    for interface_id in interface_list:
        if not interface_id:
            continue
        add_param_dict["interface_id"] = interface_id
        relation_id = Case_API.add_relation(**add_param_dict)
        interface_list = InterfaceAPI.get_interface(id=interface_id)
        the_interface = interface_list[0]
        analysis_str = ''.join([the_interface.get('interface_header'),
                                the_interface.get('interface_json_payload'),
                                the_interface.get('interface_url')])
        param_list = search_parameter(analysis_str)
        for para in param_list:
            if '==' in para:
                parameter_value = para.split('==')[1]
                parameter_name = para.split('==')[0]
            else:
                parameter_value = ''
                parameter_name = para
            Case_API.add_case_parameter_relation(relation_id=relation_id, parameter_name=parameter_name,
                                                 parameter_value=parameter_value)
    return jsonify({'success': True})
Ejemplo n.º 3
0
def modify_interface():
    """
    更新interface信息
    1. 获取原interface参数信息
    2. 将更新的interface内容写入数据库
    3. 如果新旧参数无区别, 结束并返回
    4. 如果新旧参数有区别, 更新所有use_case传给此interface的参数记录
    """
    interface_id = request.get_json().get('id')
    interface_old_info = InterfaceAPI.get_interface(id=interface_id)[0]
    InterfaceAPI.modify_interface(**request.get_json())
    interface_new_info = InterfaceAPI.get_interface(id=interface_id)[0]
    relation_list = UseCaseAPI.get_relation(interface_id=interface_id)
    old_analysis_str = ''.join([
        interface_old_info.get('interface_header'),
        interface_old_info.get('interface_json_payload'),
        interface_old_info.get('interface_url')
    ])
    new_analysis_str = ''.join([
        interface_new_info.get('interface_header'),
        interface_new_info.get('interface_json_payload'),
        interface_new_info.get('interface_url')
    ])
    old_param_list = search_parameter(old_analysis_str)
    new_param_list = search_parameter(new_analysis_str)
    update_param_list = list(set(old_param_list) ^ set(new_param_list))
    if len(update_param_list) == 0:
        return jsonify({'success': True})
    else:
        for param in update_param_list:
            if '==' in param:
                parameter_value = param.split('==')[1]
                parameter_name = param.split('==')[0]
            else:
                parameter_value = ''
                parameter_name = param
            if param in old_param_list:
                for p_relation in relation_list:
                    UseCaseAPI.del_case_parameter_relation(
                        parameter_name=parameter_name,
                        relation_id=p_relation['id'])
            else:  # 新增参数添加到各个用例中去
                for relation in relation_list:
                    kwargs = {
                        'relation_id': relation['id'],
                        'parameter_name': parameter_name,
                        'parameter_value': parameter_value
                    }
                    UseCaseAPI.add_case_parameter_relation(**kwargs)
    return jsonify({'success': True})