def getHeader(fileName:str,foldname:str) ->str: ''' :param fileName: yaml文件名 :param foldname: data目录下的二级目录 :return: ''' fold_path = os.path.join(DATA_PATH, foldname) rs = doYaml.get_data(os.path.join(fold_path, fileName)) header = rs["header"] if header == None: return None else: return header
def loginPlatform(): rs = doYaml.get_data(os.path.join(BASE_PATH, "createFlow.yaml")) url = rs["url"] + rs["path"] method = rs["method"] data = rs["LoginPlatform"] #login登录 try: result = requests.request(method, url, json=data) if result.status_code == 200: rjson = result.json() if rjson["MessageType"] == 200: rsToken = rjson["Data"]["access_token"] else: print("登录失败,请稍后再试") print(rsToken) return rsToken except Exception as e: print("错误原因是:%s" % e)
def createFlow(className: str, token: str, PlatformToken: str) -> bool: rs = doYaml.get_data(os.path.join(BASE_PATH, "createFlow.yaml")) url = 'http://192.168.110.75:8086/process/' + className header = rs["header"] Authorization = {'Authorization': token} PlatformAuthorization = {'PlatformAuthorization': PlatformToken} headers = {**header, **Authorization, **PlatformAuthorization} req = requests.get(url=url, headers=headers) try: if req.status_code == 200: result = req.text else: print("请求不成功") return result except Exception as e: print("错误原因是:%s" % e)
def getUserInfo(): rs = doYaml.get_data(os.path.join(BASE_PATH, "login.yaml")) url = URL + rs["urlgetUser"] header = rs["header"] Authorization = {'Authorization': Glob.get_value("rsToken")} headers = {**header, **Authorization} try: result = requests.get(url=url, headers=headers) if result.status_code == 200: rjson = result.json() if rjson["MessageType"] == 200: TenantId = rjson["Data"]["TenantId"] else: logging.info("获取失败,请稍后再试") except Exception as e: logging.info("错误原因是:%s" % e) return TenantId
def getSqlResult(node: str, key: str, fetch: str, OneNode=None, **kwargs) -> (list, tuple): ''' :param key: 取出sql语句对应的key :param node: 识别yaml的文件节点 :param fetch: fetchone fetchall fetchmany :param OneNode: None,默认就是返回只查询一个数据的list :param **kwargs: kwargs扩展字段,如向后叠加的 tenant_id ,带有data的会自动加上‘’ :return: ''' rs = doYaml.get_data(os.path.join(DATA_PATH, 'sqlData.yaml')) sqlQuery = rs[node][key] #拼凑字符串,带有data前缀的会自动加上单引号 expandTuple = tuple([ "'" + str(value) + "'" if key.find("data") != -1 else value for key, value in kwargs.items() ]) #兼容sql非参数化,只需sql追加tenant_id,以及参数化动态填入%s中的数据 if kwargs != {} and len(kwargs) == 1: sqlQuery = '''%s %s '%s'%s''' % (sqlQuery, 'and tenant_id =', kwargs['tenant_id'], ';') elif kwargs != {} and len(kwargs) > 1: sqlQuery = sqlQuery % expandTuple else: raise UnboundLocalError logging.info("开始查询...") logging.info("查询语句为:%s" % sqlQuery) queryResult = requestSQL.excute_select(sqlQuery, fetch) if OneNode is None: queryResultToList = [sigleResult[0] for sigleResult in queryResult] return queryResultToList else: return queryResult
def login(): rs = doYaml.get_data(os.path.join(BASE_PATH, "login.yaml")) url = URL + rs["url"] method = rs["method"] data = rs["data"] #login登录 try: result = requests.request(method, url, json=data) if result.status_code == 200: rjson = result.json() if rjson["MessageType"] == 200: rsToken = rjson["Data"]["access_token"] else: logging.info("登录失败,请稍后再试") Glob.set_value("rsToken", rsToken) except Exception as e: logging.info("错误原因是:%s" % e) yield rsToken logging.info("开始清理临时数据...")
def cre_data(): rs = doYaml.get_data(os.path.join(DATA_PATH, 'allEmployees.yaml')) checkParams = rs["checkParams"] return checkParams
def cre_data(fileName: str, foldname: str, variableParms=None, *args, **kwargs) -> list: ''' :param fileName: 配置的文件名 :param foldname: data目录下的二级目录名 :param variableParms: 上一个接口获取的数据 :param *args:扩展字段,用于delete方法 :param **kwargs:扩展字段,用于构造请求体,如kwargs['input']... :return: ''' fold_path = os.path.join(DATA_PATH, foldname) rs = doYaml.get_data(os.path.join(fold_path, fileName)) url = URL + rs["url"] if rs["url"] is not None else URL method = rs["method"] mode = rs["payload"]["mode"] variables = rs["payload"]["variables"] query = rs["query"] operationName = rs["payload"]["operationName"] header = getHeader(fileName, foldname) if mode == 'create' or mode == 'query': if variables is not None and variableParms is None: if isinstance(variables, list): list_data = [(url, variable, method, header, operationName, query) for variable in variables] else: list_data = [(url, variables, method, header, operationName, query)] elif variables is None and variableParms is not None: variables = variableParms if isinstance(variables, list): list_data = [(url, variable[0], method, header, operationName, query) if isinstance(variable, tuple) \ else (url, variable, method, header, operationName, query)\ for variable in variables] else: list_data = [(url, variables, method, header, operationName, query)] elif variables is not None and variableParms is not None: responselist = variableParms variables = Common.spliceDict(variables, responselist, **kwargs) if isinstance(variables, list): list_data = [(url, variable, method, header, operationName, query) for variable in variables] else: list_data = [(url, variables, method, header, operationName, query)] else: variable = {} list_data = [(url, variable, method, header, operationName, query)] elif mode == 'disable': variables = variableParms if isinstance(variables, list): list_data = [(url, Common.dictDataClean(variable, True, **kwargs), method, header, operationName, query) for variable in variables] else: list_data = [(url, Common.dictDataClean(variables, True, **kwargs), method, header, operationName, query)] elif mode == 'delete': variables = variableParms list_data = [(url, Common.dictDataClean(variables, False, *args, **kwargs), method, header, operationName, query)] elif mode == 'update': responselist = variableParms variables = Common.spliceDict(variables, responselist, **kwargs) if isinstance(variables, list): list_data = [(url, variable, method, header, operationName, query) for variable in variables] else: list_data = [(url, variables, method, header, operationName, query)] else: raise NameError("mode 不能为空,或者模式不对") return list_data