def get_except_data_for_sql(self, row, sql_base): oper_mysql = OperationMysql(sql_base) except_data = self.get_except(row) result = oper_mysql.search_all(except_data) # if sql_value == '': # result = oper_mysql.search_all(except_data) # else: # result = oper_mysql.search_all(except_data % sql_value) return result
def get_expcet_data(self, row): expect = self.get_expcet_data_for_excel(row) if expect == "": return None if re.match('select.+from', expect, re.M | re.I) == None: return expect else: op_mysql = OperationMysql() return op_mysql.search_one(expect)
def get_expect_data_for_mysql(self, row): sql = self.get_expect_data(row) if sql[:6] == 'select': res = OperationMysql().search_one(sql) expect_type = 'sql' else: res = sql expect_type = 'notsql' return res, expect_type
def get_expcet_data(self, row): col = int(data_config.get_expect()) expect = self.opera_excel.get_cell_value(row, col) if expect == '': expect = None elif not self.common_util.is_json(expect): op_mysql = OperationMysql() expect = op_mysql.search_one(expect) return expect
def get_all_sql_data(self, row, get_data): sql = get_data(row) # print sql # 这里做判断,预期结果内有sql命令,才去运行sql if sql != None: op_mysql = OperationMysql() res = op_mysql.search_all(sql) # return res.decode('unicode-escape') # print(res.encode('utf-8').decode('gb18030')) # print(type((res.encode('utf-8').decode('gb18030')))) return res.encode('utf-8').decode('unicode_escape') else: return None
def get_expcet_data(self, row): col = int(data_config.get_expect()) expect = self.opera_excel.get_cell_value(row, col) if expect == '': return None # 替换 p = r"\${(.+?)}" robocop = re.compile(p, re.I) temps = robocop.findall(expect) if temps: for temp in temps: # 数据库查询,不区分大小写 if temp.upper().find("select".upper()) >= 0: op_mysql = OperationMysql() res = op_mysql.search_one(temp) expect = re.sub(p, res, expect) # json替换 else: opera_json = OperetionJson() res = str(opera_json.get_data(temp)) expect = re.sub(p, res, expect) return expect
def get_expcet_data_for_mysql(self, row): op_mysql = OperationMysql() sql = self.get_expcet_data(row) res = op_mysql.search_one(sql) return res.decode('unicode-escape')
break dic_data[p] = result_db return dic_data # 递归获取 expectResponse 字段的 字典value值 def getListFromDict(self, list, dic): for i in dic: if isinstance(dic[i], dict): self.getListFromDict(list, dic[i]) else: list.append(dic[i]) return list if __name__ == '__main__': # 选择数据环境 线上/测试 db_enviroment = "test" # db_enviroment="prod" operation_mysql = OperationMysql(db_enviroment) # # 选择用例文件 # # fileName='../dataconfig/case1.xls' # # fileName = '../dataconfig/confucius.xls' fileName = 'dataconfig/management.xls' # # fileName = '../dataconfig/yunying.xls' sheetid = 0 run = RunTest(fileName=fileName, sheetid=sheetid) run.go_on_run()
def __init__(self): self.oper_excel = OperationExcel() self.opera_mysql = OperationMysql()
def update_sql(self, row): op_mysql = OperationMysql() sql = self.get_sql_data(row) res = op_mysql.update_one(sql)