def update(): """ 修改用例 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = request.json if fromData is not None: CaseEnv.query.filter(CaseEnv.uc_id == fromData["case_id"]).delete(synchronize_session=False) db.session.commit() CaseScene.query.filter(CaseScene.uc_id == fromData["case_id"]).delete(synchronize_session=False) db.session.commit() for case in fromData['envData']: case_env = CaseEnv(project_id=case['pro_id'], modules_id=case['mod_id'], env_id=case['env_id'], uc_id=fromData["case_id"]) db.session.add(case_env) db.session.commit() for scene in fromData['sceneData']: case_scene = CaseScene(project_id=scene['pro_id'], sceneList_id=scene['scene_id'],uc_id=fromData["case_id"]) db.session.add(case_scene) db.session.commit() userCase = UserCase.query.get_or_404(fromData["case_id"]) userCase.case_name = fromData['case_name'] userCase.case_desc = fromData['case_desc'] userCase.request_address = fromData['request_address'] userCase.email_address = fromData['email_address'] db.session.commit() return jsonify(common.trueReturn('', '修改成功')) else: return jsonify(result)
def add(): """ 用例新增 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = request.json if fromData is not None: case_name = fromData['case_name'] case_desc = fromData['case_desc'] request_address = fromData['request_address'] if fromData['email_address'] != None: email_address = fromData['email_address'] list_case = [] for case in fromData['envData']: case_env = CaseEnv(project_id=case['pro_id'], modules_id=case['mod_id'], env_id=case['env_id']) list_case.append(case_env) list_scene = [] for scene in fromData['sceneData']: case_scene = CaseScene(project_id=scene['pro_id'], sceneList_id=scene['scene_id']) list_scene.append(case_scene) user_case = UserCase(case_name=case_name, case_desc=case_desc, email_address=email_address, request_address=str(request_address), case_env=list_case, caseScene=list_scene) db.session.add(user_case) db.session.commit() return jsonify(common.trueReturn('', '用例新增成功')) else: return jsonify(result)
def updateModular(): """ 模块修改 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: mod_id = request.json.get('mod_id') mod_name = request.json.get('mod_name') mod_desc = request.json.get('mod_desc') pro_id = request.json.get('pro_id') status = request.json.get('status') modules = Modules.query.get_or_404(mod_id) modules.modules_name = mod_name modules.modules_desc = mod_desc modules.status = status modules.project_id = pro_id modules.update_time = datetime.now() if status: modules.status = '1' else: modules.status = '2' db.session.commit() return jsonify(common.trueReturn('', '模块修改成功')) else: return jsonify(result)
def updateProject(): """ 项目修改 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: project_id = request.json.get('project_id') project_name = request.json.get('project_name') project_desc = request.json.get('project_desc') status = request.json.get('status') project = Project.query.get_or_404(project_id) project.project_name = project_name if status: project.status = 1 else: project.status = 2 project.project_desc = project_desc project.update_time = datetime.now() db.session.commit() return jsonify(common.trueReturn('', '项目修改成功')) else: return jsonify(result)
def index(page=1): """ 项目查询 :param page: 页数 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) param = [] page = fromData['page'] project_name = fromData['proname'] scenename = fromData['scenename'] # 拼接查询条件 stmt = Project.query.with_entities(Project.project_id).filter( Project.project_name.like("%" + project_name + "%")).subquery() if scenename != 'None' and len(scenename) > 0: param.append(SceneList.scene_name.like("%" + scenename + "%")) # 每页显示数 per_page = current_app.config['INTERFACE_PER_PAGE'] # 分页对象 pagination = db.session.query(SceneList).join( stmt, SceneList.project_id == stmt.c.project_id).filter(*param).group_by( SceneList.sceneList_id).paginate(page, per_page=per_page) # 总条数 count = db.session.query(SceneList).join( stmt, SceneList.project_id == stmt.c.project_id).filter(*param).group_by( SceneList.sceneList_id).count() # # 总页数 page_count = math.ceil(count / per_page) # 当前页数的记录列表 sceneList = pagination.items scene_list = [] for item in sceneList: scene_dic = {} scene_dic['sceneList_id'] = item.sceneList_id scene_dic['scene_name'] = item.scene_name scene_dic['project_id'] = item.project_id project = Project.query.with_entities(Project.project_name).filter( Project.project_id == item.project_id).all() scene_dic['project_name'] = project[0].project_name scene_dic['scene_desc'] = item.scene_desc scene_list.append(scene_dic) list_dic = {} list_dic['list'] = scene_list list_dic['count'] = count list_dic['page_count'] = page_count list_dic['per_page'] = per_page return jsonify(common.trueReturn(list_dic, '场景查询成功')) else: return jsonify(result)
def delete(): """ 删除项目 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: project_id = request.json.get('project_id') Project.query.filter(Project.project_id == project_id).delete( synchronize_session=False) db.session.commit() db.session.close() Modules.query.filter(Modules.project_id == project_id).delete( synchronize_session=False) db.session.commit() db.session.close() environment = Environment.query.with_entities( Environment.env_id).filter( Environment.project_id == project_id).all() for env in environment: parameter = Parameter.query.filter( Parameter.env_id == env.env_id).first() if parameter is not None: Parameter.query.filter(Parameter.env_id == env.env_id).delete( synchronize_session=False) db.session.commit() db.session.close() # 删除 调用接口 transfer = Transfer.query.filter( Transfer.tra_need_env_id == env.env_id).first() if transfer is not None: transfer_all = Transfer.query.filter( Transfer.tra_need_env_id == env.env_id).all() for tar in transfer_all: db.session.delete(tar) db.session.commit() db.session.close() # 删除信息头 header = HeaderValue.query.filter( HeaderValue.env_id == env.env_id).first() if header is not None: HeaderValue.query.filter( HeaderValue.env_id == env.env_id).delete( synchronize_session=False) db.session.commit() db.session.close() Environment.query.filter(Environment.project_id == project_id).delete( synchronize_session=False) db.session.commit() db.session.close() return jsonify(common.trueReturn('', '项目删除成功')) else: return jsonify(result)
def delete(): result = Auth.identify(Auth, request) if result['status'] and result['data']: env_id = request.json.get('env_id') Environment.query.get_or_404(env_id) Environment.query.filter_by(env_id=env_id).delete() db.session.commit() return jsonify(common.trueReturn('', '接口删除成功')) else: return jsonify(result)
def add(): """ 模块接口 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: sceneList = request.json.get("sceneList") list_sceneEnvData = [] index_num = 1 for sceneEnvData in sceneList['sceneEnvData']: list_header = [] for headerData in sceneEnvData['headerData']: herader = HeaderValue(header_name=headerData['header_name'], header_value=headerData['header_value']) list_header.append(herader) list_check = [] check = Check(check_verification_code=sceneEnvData['check_body'] ['check_verification_code'], check_agreement_relation=sceneEnvData['check_body'] ['check_agreement_relation'], check_verification_value=sceneEnvData['check_body'] ['check_verification_value']) list_check.append(check) variableList = [] for var in sceneEnvData['variableData']: variable = Variable(var_regexp=var['var_regexp'], var_name=var['var_name']) variableList.append(variable) sceneEnv = SceneEnv(project_id=sceneEnvData['project_id'], modules_id=sceneEnvData['modules_id'], env_id=sceneEnvData['env_id'], scene_body=sceneEnvData['bodyData'], header=list_header, check=list_check, variable=variableList, number=index_num) index_num += 1 list_sceneEnvData.append(sceneEnv) sceneList = SceneList(scene_name=sceneList['scene_name'], project_id=sceneList['project_id'], scene_desc=sceneList['scene_desc'], sceneEnv=list_sceneEnvData) db.session.add(sceneList) db.session.commit() return jsonify(common.trueReturn('', '场景新增成功')) else: return jsonify(result)
def selectUpdat(): result = Auth.identify(Auth, request) if result['status'] and result['data']: sceneList_id = request.json.get('sceneList_id') sceneList = SceneList.query.get_or_404(sceneList_id) sceneJson = {} sceneJson['scene_name'] = sceneList.scene_name sceneJson['project_id'] = sceneList.project_id sceneJson['scene_desc'] = sceneList.scene_desc sceneEnvData = [] for sceneEnv in sceneList.sceneEnv: scene = {} scene['scene_id'] = sceneEnv.scene_id scene['project_id'] = sceneEnv.project_id scene['modules_id'] = sceneEnv.modules_id scene['env_id'] = sceneEnv.env_id env = Environment.query.filter( Environment.env_id == sceneEnv.env_id).all() scene['env_name'] = env[0].env_name scene['project_name'] = env[0].project.project_name scene['modules_name'] = env[0].modules.modules_name scene['bodyData'] = sceneEnv.scene_body headerData = [] for sceneHeader in sceneEnv.header: header = {} header['header_name'] = sceneHeader.header_name header['header_value'] = sceneHeader.header_value header['header_id'] = sceneHeader.header_id headerData.append(header) scene['headerData'] = headerData check_body = {} check_body['check_verification_code'] = sceneEnv.check[ 0].check_verification_code check_body['check_agreement_relation'] = sceneEnv.check[ 0].check_agreement_relation check_body['check_verification_value'] = sceneEnv.check[ 0].check_verification_value scene['check_body'] = check_body variableData = [] for sceneVariable in sceneEnv.variable: variable = {} variable['var_regexp'] = sceneVariable.var_regexp variable['var_id'] = sceneVariable.var_id variable['var_name'] = sceneVariable.var_name variable['var_value'] = sceneVariable.var_value variableData.append(variable) scene['variableData'] = variableData sceneEnvData.append(scene) sceneJson['sceneEnvData'] = sceneEnvData return jsonify(common.trueReturn(sceneJson, '查询成功')) else: return jsonify(result)
def index(page=1): """ 项目查询 :param page: 页数 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) param = [] page = fromData['page'] # 拼接查询条件 if fromData['project_name'] != 'None' and len( fromData['project_name']) > 0: param.append( Project.project_name.like("%" + fromData['project_name'] + "%")) if fromData['status'] != 'None' and fromData['status'] != '0': param.append(Project.status == fromData['status']) # 每页显示数 per_page = current_app.config['INTERFACE_PER_PAGE'] # 分页对象 pagination = Project.query.filter(*param).paginate(page, per_page=per_page) # 总条数 count = Project.query.filter(*param).count() # # 总页数 page_count = math.ceil(count / per_page) # print('总页数 ', page_count) # 当前页数的记录列表 project = pagination.items project_list = [] for item in project: project_dic = {} project_dic['project_id'] = item.project_id project_dic['project_name'] = item.project_name project_dic['project_desc'] = item.project_desc project_dic['status'] = item.status project_list.append(project_dic) list_dic = {} list_dic['list'] = project_list list_dic['count'] = count list_dic['page_count'] = page_count list_dic['per_page'] = per_page return jsonify(common.trueReturn(list_dic, '项目查询成功')) else: return jsonify(result)
def getProject(): """ 查询单个项目 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: project_id = request.json.get('project_id') project = Project.query.get_or_404(project_id) project_dic = {} project_dic['project_id'] = project.project_id project_dic['project_name'] = project.project_name project_dic['project_desc'] = project.project_desc project_dic['status'] = project.status return jsonify(common.trueReturn(project_dic, '查询成功')) else: return jsonify(result)
def delete(): result = Auth.identify(Auth, request) if result['status'] and result['data']: sceneList_id = request.json.get('sceneList_id') SceneList.query.filter_by(sceneList_id=sceneList_id).delete() db.session.commit() scene_id_All = SceneEnv.query.with_entities(SceneEnv.scene_id).filter( SceneEnv.sceneList_id == sceneList_id).all() for scene in scene_id_All: # 删除数据 checkList = Check.query.filter( Check.scene_id == scene.scene_id).first() if checkList is not None: Check.query.filter(Check.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() headerList = HeaderValue.query.filter( HeaderValue.scene_id == scene.scene_id).first() if headerList is not None: HeaderValue.query.filter( HeaderValue.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() variableList = Variable.query.filter( Variable.scene_id == scene.scene_id).first() if variableList is not None: Variable.query.filter( Variable.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() sceneEnvList = SceneEnv.query.filter( SceneEnv.scene_id == scene.scene_id).first() if sceneEnvList is not None: SceneEnv.query.filter( SceneEnv.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() return jsonify(common.trueReturn('', '场景删除成功')) else: return jsonify(result)
def index(): """ 用例查询 :param page: 页数 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) page = fromData['page'] case_name = fromData['case_name'] param = [] # form = CaseSelectForm() # case_name = "" # param = [] # if request.method == 'POST': # case_name = form.case_name.data param.append(UserCase.case_name.like("%" + case_name + "%")) # 每页显示数 per_page = current_app.config['INTERFACE_PER_PAGE'] # 分页对象 pagination = UserCase.query.filter(*param).paginate(page, per_page=per_page) # 总条数 count = UserCase.query.filter(*param).count() page_count = math.ceil(count / per_page) caseList = pagination.items case_list = [] for item in caseList: case_dic = {} case_dic['case_id'] = item.uc_id case_dic['case_name'] = item.case_name case_dic['case_desc'] = item.case_desc case_dic['request_address'] = item.request_address case_dic['email_address'] = item.email_address case_list.append(case_dic) list_dic = {} list_dic['list'] = case_list list_dic['count'] = count list_dic['page_count'] = page_count list_dic['per_page'] = per_page return jsonify(common.trueReturn(list_dic, '接口查询成功')) else: return jsonify(result)
def select_project(): """ 根据项目查询模块 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: project = Project.query.with_entities(Project.project_id, Project.project_name).all() project_dict = [] for p, k in project: pro_json = {} pro_json['project_id'] = p pro_json['project_name'] = k project_dict.append(pro_json) return jsonify(common.trueReturn(project_dict, '项目查询成功')) else: return jsonify(result)
def getProject(): """ 查询单个模块 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: mod_id = request.json.get('mod_id') modules = Modules.query.get_or_404(mod_id) modules_dic = {} modules_dic['modules_id'] = modules.modules_id modules_dic['modules_name'] = modules.modules_name modules_dic['modules_desc'] = modules.modules_desc modules_dic['project_id'] = modules.project.project_id modules_dic['status'] = modules.status return jsonify(common.trueReturn(modules_dic, '查询成功')) else: return jsonify(result)
def caseAll(): """ 用例全部查询 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: case = UserCase.query.filter().all() case_list = [] for item in case: case_dic = {} case_dic['case_id'] = item.uc_id case_dic['case_name'] = item.case_name case_dic['case_desc'] = item.case_desc case_dic['request_address'] = item.request_address case_list.append(case_dic) list_dic = {} list_dic['list'] = case_list return jsonify(common.trueReturn(list_dic, '接口查询成功'))
def delete(): """ 删除Case :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = request.json user_case = UserCase.query.get_or_404(fromData['case_id']) db.session.delete(user_case) db.session.commit() Report.query.filter_by(uc_id=fromData['case_id']).delete(synchronize_session=False) db.session.commit() CaseScene.query.filter(CaseScene.uc_id == fromData["case_id"]).delete(synchronize_session=False) db.session.commit() return jsonify(common.trueReturn('', '用例删除成功')) else: return jsonify(result)
def updateCase(): result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = request.json user_case = UserCase.query.get_or_404(fromData['case_id']) caseJson = {} caseJson['case_name'] = user_case.case_name caseJson['case_desc'] = user_case.case_desc caseJson['case_id'] = user_case.uc_id caseJson['request_address'] = user_case.request_address caseJson['email_address'] = user_case.email_address case_jsonarray = [] for case_env in user_case.case_env: case_env_dict = {} case_env_dict['case_id'] = case_env.case_id case_env_dict['env_id'] = case_env.env_id env = Environment.query.get_or_404(case_env.env_id) case_env_dict['env_name'] = env.env_name case_env_dict['mod_id'] = case_env.modules_id modules = Modules.query.get_or_404(case_env.modules_id) case_env_dict['mod_name'] = modules.modules_name case_env_dict['pro_id'] = case_env.project_id project = Project.query.get_or_404(case_env.project_id) case_env_dict['pro_name'] = project.project_name case_jsonarray.append(case_env_dict) case_scene_list = [] for case_scene in user_case.caseScene: case_scene_dict = {} case_scene_dict['pro_id'] = case_scene.project_id project = Project.query.get_or_404(case_scene.project_id) case_scene_dict['pro_name'] = project.project_name case_scene_dict['scene_id'] = case_scene.sceneList_id scene_name = SceneList.query.get_or_404(case_scene.caseScene_id) case_scene_dict['scene_name'] = scene_name.scene_name case_scene_list.append(case_scene_dict) caseJson['case_env_list'] = json.dumps(case_jsonarray, ensure_ascii=False) caseJson['case_scene_list'] = json.dumps(case_scene_list, ensure_ascii=False) return jsonify(common.trueReturn(caseJson, '用例查询成功')) else: return jsonify(result)
def select_modular(): """ 根据项目查询模块 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) project_id = fromData['project_id'] model = Modules.query.with_entities( Modules.modules_id, Modules.modules_name).filter( Modules.project_id == project_id).all() model_dict = [] for p, k in model: model_json = {} model_json['modules_id'] = p model_json['modules_name'] = k model_dict.append(model_json) return jsonify(common.trueReturn(model_dict, '模块查询成功')) else: return jsonify(result)
def select_env(): """ 根据模块查询接口 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) modules_id = fromData['modules_id'] env = Environment.query.with_entities( Environment.env_id, Environment.env_name).filter( Environment.modules_id == modules_id).all() env_dict = [] for p, k in env: env_json = {} env_json['env_id'] = p env_json['env_name'] = k env_dict.append(env_json) return jsonify(common.trueReturn(env_dict, '接口查询成功')) else: return jsonify(result)
def select_modular(): """ 根据项目查询场景 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) project_id = fromData['project_id'] model = SceneList.query.with_entities( SceneList.sceneList_id, SceneList.scene_name).filter( SceneList.project_id == project_id).all() sceneList_dict = [] for p, k in model: sceneList_json = {} sceneList_json['sceneList_id'] = p sceneList_json['scene_name'] = k sceneList_dict.append(sceneList_json) return jsonify(common.trueReturn(sceneList_dict, '场景查询成功')) else: return jsonify(result)
def add(): """ 项目新增 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: project_name = request.json.get('project_name') project_desc = request.json.get('project_desc') status = request.json.get('status') if status: status = '1' else: status = '2' project = Project(project_name=project_name, project_desc=project_desc, status=status) db.session.add(project) db.session.commit() return jsonify(common.trueReturn('', '项目新增成功')) else: return jsonify(result)
def start(): """ 启动执行用例 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: report_case_type = str(uuid.uuid1()) fromData = request.json report_create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') test_case(fromData["case_id"], report_case_type, fromData["request_address"], report_create_time) strbody = '用例' + str(fromData["case_id"]) + '执行成功' execlName = report_case_type.replace('-', '') getExecl(report_case_type=report_case_type, execlName=execlName) if fromData["email_address"] != None and len(fromData["email_address"]) > 0: email_address = fromData["email_address"] startPath = os.path.join(current_path, 'logs\\' + execlName + '_interface.xlsx') send_mail_with_file(filepath=startPath, filename=u"interface.xlsx", subject=u'接口自动化测试', to_addr=email_address) return jsonify(common.trueReturn('', strbody)) else: return jsonify(result)
def add(): """ 模块新增 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: mod_name = request.json.get('mod_name') mod_desc = request.json.get('mod_desc') status = request.json.get('status') pro_id = request.json.get('pro_id') if status: status = '1' else: status = '2' modules = Modules(modules_name=mod_name, modules_desc=mod_desc, status=status, project_id=pro_id) db.session.add(modules) db.session.commit() return jsonify(common.trueReturn('', '模块新增成功')) else: return jsonify(result)
def update(): """ 模块修改 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = request.json # 删除参数 parameter = Parameter.query.filter( Parameter.env_id == fromData["env_id"]).first() if parameter is not None: Parameter.query.filter( Parameter.env_id == fromData["env_id"]).delete( synchronize_session=False) db.session.commit() # 删除 调用接口 transfer = Transfer.query.filter( Transfer.tra_need_env_id == fromData["env_id"]).first() if transfer is not None: transfer_all = Transfer.query.filter( Transfer.tra_need_env_id == fromData["env_id"]).all() for tar in transfer_all: db.session.delete(tar) db.session.commit() # Transfer.query.filter(Transfer.tra_need_env_id == fromData["env_id"]).delete(synchronize_session=False) # db.session.commit() # 删除信息头 header = HeaderValue.query.filter( HeaderValue.env_id == fromData["env_id"]).first() if header is not None: HeaderValue.query.filter( HeaderValue.env_id == fromData["env_id"]).delete( synchronize_session=False) db.session.commit() # 接口调用模块 for transfer in fromData['tra_table']: list_variables = [] for variables in transfer['varTable']: variable = Variable(var_regexp=variables['var_regexp'], var_name=variables['var_name']) list_variables.append(variable) transfer_db = Transfer(tra_modulated_env_id=transfer['tar_env_id'], tra_need_env_id=fromData["env_id"], variable=list_variables) db.session.add(transfer_db) db.session.commit() # list_transfer.append(transfer_db) # 信息头新增 if len(fromData['headerValue']): for hear in fromData['headerValue']: hearders = HeaderValue(header_name=hear['header_name'], header_value=hear['header_value'], env_id=fromData["env_id"]) db.session.add(hearders) db.session.commit() # 接口参数模块 if len(fromData['parm_table']): for parm in fromData['parm_table']: parameter = Parameter( par_variable_name=parm['env_parameter_par_variable_name'], par_cn_name=parm['env_parameter_par_cn_name'], par_us_name=parm['env_parameter_par_en_name'], par_type=parm['env_parameter_par_type'], par_range=parm['env_parameter_par_range'], par_date_type=str(parm['par_date_type']), par_start_date=parm['par_start_date'], par_end_date=parm['par_end_date'], par_required=parm['env_parameter_par_required'], par_correct=parm['env_parameter_par_correct_value'], par_correct_list=parm['par_correct_list'], env_id=fromData["env_id"]) db.session.add(parameter) db.session.commit() # 修改接口主表 environment = Environment.query.get_or_404(fromData["env_id"]) environment.env_name = fromData['env_name'] environment.env_desc = fromData['env_desc'] environment.env_status = fromData['env_status'] environment.env_agreement = fromData['env_agreement'] environment.env_transmission = fromData['env_transmission'] environment.env_ip = fromData['env_ip'] environment.env_port = fromData['env_port'] environment.env_path = fromData['env_path'] environment.env_bodyData = fromData['env_bodyData'] environment.env_verification = fromData['env_verification'] # environment.env_complete = fromData['env_complete'] environment.project_id = fromData['project_id'] environment.modules_id = fromData['modules_id'] db.session.commit() return jsonify(common.trueReturn('', '接口编辑成功')) else: return jsonify(result)
def index(page=1): """ 模块查询 :param page: 页数 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) param = [Modules.del_status != '0'] page = fromData['page'] project_name = fromData['proname'] modules_name = fromData['modname'] status = fromData['status'] # 拼接查询条件 stmt = Project.query.with_entities(Project.project_id).filter( Project.project_name.like("%" + project_name + "%")).subquery() if modules_name != 'None' and len(modules_name) > 0: param.append(Modules.modules_name.like("%" + modules_name + "%")) if status != 'None' and status != '0': param.append(Modules.status == status) # 每页显示数 per_page = current_app.config['INTERFACE_PER_PAGE'] # 分页对象 pagination = db.session.query(Modules).join( stmt, Modules.project_id == stmt.c.project_id).filter(*param).group_by( Modules.modules_id).paginate(page, per_page=per_page) # 总条数 count = db.session.query(Modules).join( stmt, Modules.project_id == stmt.c.project_id).filter(*param).group_by( Modules.modules_id).count() # 当前页数的记录列表 page_count = math.ceil(count / per_page) pro_list = Project.query.all() modular = pagination.items modular_list = [] for item in modular: modular_dic = {} modular_dic['mod_id'] = item.modules_id modular_dic['pro_name'] = item.project.project_name modular_dic['mod_name'] = item.modules_name modular_dic['mod_desc'] = item.modules_desc modular_dic['status'] = item.status modular_list.append(modular_dic) list_dic = {} list_dic['list'] = modular_list list_dic['count'] = count list_dic['page_count'] = page_count list_dic['per_page'] = per_page project = pro_list project_list = [] for item in project: project_dic = {} project_dic['project_id'] = item.project_id project_dic['project_name'] = item.project_name project_dic['project_desc'] = item.project_desc project_dic['status'] = item.status project_list.append(project_dic) list_dic['pro_list'] = project_list return jsonify(common.trueReturn(list_dic, '模块查询成功')) else: return jsonify(result)
def update(): result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = request.json.get("sceneList") scene_id_All = SceneEnv.query.with_entities(SceneEnv.scene_id).filter( SceneEnv.sceneList_id == fromData["sceneList_id"]).all() for scene in scene_id_All: # 删除数据 checkList = Check.query.filter( Check.scene_id == scene.scene_id).first() if checkList is not None: Check.query.filter(Check.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() headerList = HeaderValue.query.filter( HeaderValue.scene_id == scene.scene_id).first() if headerList is not None: HeaderValue.query.filter( HeaderValue.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() variableList = Variable.query.filter( Variable.scene_id == scene.scene_id).first() if variableList is not None: Variable.query.filter( Variable.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() sceneEnvList = SceneEnv.query.filter( SceneEnv.scene_id == scene.scene_id).first() if sceneEnvList is not None: SceneEnv.query.filter( SceneEnv.scene_id == scene.scene_id).delete( synchronize_session=False) db.session.commit() index_num = 1 for sceneEnvData in fromData['sceneEnvData']: list_header = [] for headerData in sceneEnvData['headerData']: herader = HeaderValue(header_name=headerData['header_name'], header_value=headerData['header_value']) list_header.append(herader) list_check = [] check = Check(check_verification_code=sceneEnvData['check_body'] ['check_verification_code'], check_agreement_relation=sceneEnvData['check_body'] ['check_agreement_relation'], check_verification_value=sceneEnvData['check_body'] ['check_verification_value']) list_check.append(check) variableList = [] for var in sceneEnvData['variableData']: variable = Variable(var_regexp=var['var_regexp'], var_name=var['var_name']) variableList.append(variable) sceneEnv = SceneEnv(project_id=sceneEnvData['project_id'], modules_id=sceneEnvData['modules_id'], env_id=sceneEnvData['env_id'], scene_body=sceneEnvData['bodyData'], header=list_header, check=list_check, variable=variableList, sceneList_id=fromData["sceneList_id"], number=index_num) db.session.add(sceneEnv) db.session.commit() index_num += 1 sceneList = SceneList.query.get_or_404(fromData["sceneList_id"]) sceneList.scene_name = fromData['scene_name'] sceneList.project_id = fromData['project_id'] sceneList.scene_desc = fromData['scene_desc'] db.session.commit() return jsonify(common.trueReturn('', '场景编辑成功')) else: return jsonify(result)
def updateEnv(): result = Auth.identify(Auth, request) if result['status'] and result['data']: env_id = request.json.get('env_id') env = Environment.query.get_or_404(env_id) envJson = {} envJson['project_id'] = env.project_id envJson['modules_id'] = env.modules_id envJson['env_name'] = env.env_name envJson['env_desc'] = env.env_desc envJson['env_transmission'] = env.env_transmission envJson['env_agreement'] = env.env_agreement envJson['env_ip'] = env.env_ip envJson['env_path'] = env.env_path envJson['env_port'] = env.env_port envJson['env_bodyData'] = env.env_bodyData envJson['env_verification'] = env.env_verification envJson['env_status'] = env.env_status envJson['env_complete'] = env.env_complete envJson['env_id'] = env.env_id transfer_jsonarray = [] for transfer in env.transfer: transfer_dict = {} transfer_dict['tra_transfer_id'] = transfer.tra_transfer_id transfer_dict['tra_need_env_id'] = transfer.tra_need_env_id transfer_dict['tar_env_id'] = transfer.tra_modulated_env_id tra_modulated_env = Environment.query.get_or_404( transfer.tra_modulated_env_id) transfer_dict['tar_pro_id'] = tra_modulated_env.project_id transfer_dict['tar_mod_id'] = tra_modulated_env.modules_id transfer_dict[ 'tar_pro_name'] = tra_modulated_env.project.project_name transfer_dict[ 'tar_mod_name'] = tra_modulated_env.modules.modules_name transfer_dict['tar_env_name'] = tra_modulated_env.env_name variable_list = [] for variable in transfer.variable: variable_dict = {} variable_dict['var_id'] = variable.var_id variable_dict['transfer_id'] = variable.transfer_id variable_dict['var_name'] = variable.var_name variable_dict['var_regexp'] = variable.var_regexp variable_dict['var_value'] = variable.var_value variable_list.append(variable_dict) transfer_dict['varTable'] = variable_list transfer_jsonarray.append(transfer_dict) parameter_list = [] for parameter in env.parameter: parameter_dict = {} parameter_dict[ 'env_parameter_par_variable_name'] = parameter.par_variable_name parameter_dict['env_parameter_par_cn_name'] = parameter.par_cn_name parameter_dict[ 'env_parameter_par_correct_value'] = parameter.par_correct parameter_dict['par_date_type'] = parameter.par_date_type parameter_dict['par_end_date'] = parameter.par_end_date parameter_dict['par_id'] = parameter.par_id parameter_dict['env_parameter_par_range'] = parameter.par_range parameter_dict[ 'env_parameter_par_required'] = parameter.par_required parameter_dict['par_start_date'] = parameter.par_start_date parameter_dict['env_parameter_par_type'] = parameter.par_type parameter_dict['env_parameter_par_en_name'] = parameter.par_us_name parameter_dict['par_correct_list'] = parameter.par_correct_list parameter_dict['env_id'] = parameter.env_id # parameter_dict['env_parameter_par_variable'] = parameter.par_variable parameter_list.append(parameter_dict) headerValue_list = [] for header in env.headerValue: headerValue_dict = {} headerValue_dict['header_name'] = header.header_name headerValue_dict['header_value'] = header.header_value headerValue_dict['env_id'] = header.env_id headerValue_list.append(headerValue_dict) envJson['tra_table'] = json.dumps(transfer_jsonarray, ensure_ascii=False) envJson['parm_table'] = json.dumps(parameter_list, ensure_ascii=False) envJson['headerValue'] = json.dumps(headerValue_list, ensure_ascii=False) return jsonify(common.trueReturn(envJson, '查询成功')) else: return jsonify(result)
def add(): """ 模块接口 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: list_transfer = [] for transfer in request.json.get("tra_table"): list_variables = [] for variables in transfer['varTable']: variable = Variable(var_regexp=variables['var_regexp'], var_name=variables['var_name']) list_variables.append(variable) transfer_db = Transfer(tra_modulated_env_id=transfer['tar_env_id'], variable=list_variables) list_transfer.append(transfer_db) list_parm = [] for parm in request.json.get('parm_table'): parameter = Parameter( par_variable_name=parm['env_parameter_par_variable_name'], par_cn_name=parm['env_parameter_par_cn_name'], par_us_name=parm['env_parameter_par_en_name'], par_type=parm['env_parameter_par_type'], par_range=parm['env_parameter_par_range'], par_date_type=str(parm['par_date_type']), par_start_date=parm['par_start_date'], par_end_date=parm['par_end_date'], par_required=parm['env_parameter_par_required'], par_correct=parm['env_parameter_par_correct_value'], par_correct_list=parm['par_correct_list'], ) list_parm.append(parameter) headerList = [] if len(request.json.get('headerValue')): for hear in request.json.get('headerValue'): hearders = HeaderValue(header_name=hear['header_name'], header_value=hear['header_value']) headerList.append(hearders) env = Environment( env_name=request.json.get('env_name'), env_desc=request.json.get('env_desc'), env_status=request.json.get('env_status'), env_agreement=request.json.get('env_agreement'), env_transmission=request.json.get('env_transmission'), env_ip=request.json.get('env_ip'), env_port=request.json.get('env_port'), env_path=request.json.get('env_path'), env_bodyData=request.json.get('env_bodyData'), env_verification=request.json.get('env_verification'), env_complete=request.json.get('env_complete'), project_id=request.json.get('project_id'), modules_id=request.json.get('modules_id'), parameter=list_parm, transfer=list_transfer, headerValue=headerList) db.session.add(env) db.session.commit() return jsonify(common.trueReturn('', '接口新增成功')) else: return jsonify(result)
def index(page=1): """ 接口查询 :param page: 页数 :return: """ result = Auth.identify(Auth, request) if result['status'] and result['data']: fromData = json.loads(request.args['0']) param = [Environment.env_del_status != '0'] page = fromData['page'] project_name = fromData['proname'] modules_name = fromData['modname'] env_name = fromData['envname'] status = fromData['status'] # 拼接查询条件 project = Project.query.with_entities(Project.project_id).filter( Project.project_name.like("%" + project_name + "%")).subquery() modules = Modules.query.with_entities(Modules.modules_id).filter( Modules.modules_name.like("%" + modules_name + "%")).subquery() if env_name != 'None' and len(env_name) > 0: param.append(Environment.env_name.like("%" + env_name + "%")) if status != 'None' and status != '0': param.append(Environment.env_status == status) # 每页显示数 per_page = current_app.config['INTERFACE_PER_PAGE'] # 分页对象 pagination = Environment.query.join( project, Environment.project_id == project.c.project_id).join( modules, Environment.modules_id == modules.c.modules_id).filter( *param).group_by(Environment.env_id).paginate( page, per_page=per_page) # 总条数 count = Environment.query.join( project, Environment.project_id == project.c.project_id).join( modules, Environment.modules_id == modules.c.modules_id).filter( *param).group_by(Environment.env_id).count() page_count = math.ceil(count / per_page) environment = pagination.items env_list = [] for item in environment: env_dic = {} env_dic['env_id'] = item.env_id env_dic['env_name'] = item.env_name env_dic['env_desc'] = item.env_desc env_dic['env_status'] = item.env_status env_dic['env_agreement'] = item.env_agreement env_dic['env_transmission'] = item.env_transmission env_dic['env_ip'] = item.env_ip env_dic['env_port'] = item.env_port env_dic['env_mode'] = item.env_mode env_dic['env_path'] = item.env_path env_dic['env_bodyData'] = item.env_bodyData env_dic['env_verification'] = item.env_verification env_dic['env_complete'] = item.env_complete env_dic['modules_id'] = item.modules.modules_id env_dic['project_id'] = item.project.project_id env_dic['project_name'] = item.project.project_name env_dic['modules_name'] = item.modules.modules_name env_list.append(env_dic) pro_list = Project.query.all() project = pro_list project_list = [] for item in project: project_dic = {} project_dic['project_id'] = item.project_id project_dic['project_name'] = item.project_name project_dic['project_desc'] = item.project_desc project_dic['status'] = item.status project_list.append(project_dic) list_dic = {} list_dic['count'] = count list_dic['page_count'] = page_count list_dic['per_page'] = per_page list_dic['list'] = env_list list_dic['pro_list'] = project_list return jsonify(common.trueReturn(list_dic, '接口查询成功')) else: return jsonify(result)