()
return jsonify({'msg': '导入成功', 'status': 1})
导入接口信息
导入接口信息
导入接口信息
def file_change():
    """ 导入接口信息 """
    # 导入功能太过简单，所以前端屏蔽了111
    data = request.json
    project_name = data.get('projectName')
    module_id = data.get('moduleId')
    if not module_id and not project_name:
        return jsonify({'msg': '项目和模块不能为空', 'status': 0})
    import_format = data.get('importFormat')
    if not import_format:
        return jsonify({'msg': '请选择文件格式', 'status': 0})

    import_format = 'har' if import_format == 'HAR' else 'json'
    project_data = Project.query.filter_by(name=project_name).first()
    host = json.loads(project_data.host)

    import_api_address = data.get('importApiAddress')
    if not import_api_address:
        return jsonify({'msg': '请上传文件', 'status': 0})
    har_parser = HarParser(import_api_address, import_format)
    case_num = auto_num(data.get('caseNum'), ApiMsg, module_id=module_id)
    for msg in har_parser.testset:
        # status_url = msg['test']['url'].replace(msg['test']['name'], '')
        # msg['test']['url'] = msg['test']['name']
        # print(msg['test']['status_url'])
        for h in host:
            if msg['status_url'] in h:
                msg['status_url'] = host.index(h)
                break
        else:
            msg['status_url'] = '0'
        new_case = ApiMsg(project_id=project_data.id, module_id=module_id, num=case_num, **msg)
        db.session.add(new_case)
        db.session.commit()
        case_num += 1
    return jsonify({'msg': '导入成功', 'status': 1})
def file_change ( ) : # 导入功能太过简单，所以前端屏蔽了111 data = request . json project_name = data . get ( 'projectName' ) module_id = data . get ( 'moduleId' ) if not module_id and not project_name : return jsonify ( { 'msg' : '项目和模块不能为空', 'status': 0}) import_format = data . get ( 'importFormat' ) if not import_format : return jsonify ( { 'msg' : '请选择文件格式', 'status': 0} ) import_format = 'har' if import_format == 'HAR' else 'json' project_data = Project . query . filter_by ( name = project_name ) . first ( ) host = json . loads ( project_data . host ) import_api_address = data . get ( 'importApiAddress' ) if not import_api_address : return jsonify ( { 'msg' : '请上传文件', 'status' : 0}) har_parser = HarParser ( import_api_address , import_format ) case_num = auto_num ( data . get ( 'caseNum' ) , ApiMsg , module_id = module_id ) for msg in har_parser . testset : # status_url = msg['test']['url'].replace(msg['test']['name'], '') # msg['test']['url'] = msg['test']['name'] # print(msg['test']['status_url']) for h in host : if msg [ 'status_url' ] in h : msg [ 'status_url' ] = host . index ( h ) break else : msg [ 'status_url' ] = '0' new_case = ApiMsg ( project_id = project_data . id , module_id = module_id , num = case_num , * * msg ) db . session . add ( new_case ) db . session . commit ( ) case_num += 1 return jsonify ( { 'msg' : '导入成功', 'statu s : 1})