コード例 #1
0
 def __init__(self):
     self.log = Log.MyLog()
     self.oper_j = operate_json.OperateJson()
     self.conf = Config.Config()
     self.excel = ExcelHandler.ExcelHandler()
     self.reqe = req_reload.ReqReload()
     self.test = Assert.Assertions()
コード例 #2
0
class ExcelHandler(object):
    '''
    关于Excel表的操作
    '''
    oper_j = operate_json.OperateJson()
    con = Config.Config()

    def get_excel_data(self, case_desc):
        '''
        过滤excel中不必要的数据
        :param case_desc: 通过excel中的case_description来过滤用例
        :return:
        '''
        # 获取到book对象
        book = xlrd.open_workbook(Config.TEST_CASE_PATH)
        sheet = book.sheet_by_index(0)
        # sheet = book.sheet_by_name('接口自动化用例')
        # sheets = book.sheets()  # 获取所有的sheet对象

        rows, cols = sheet.nrows, sheet.ncols
        l = []
        # print(sheet.row_values(0))
        title = sheet.row_values(0)
        # print(title)
        # 获取其他行
        for i in range(1, rows):
            # print(sheet.row_values(i))
            if case_desc in sheet.row_values(i):
                l.append(dict(zip(title, sheet.row_values(i))))
        return l
コード例 #3
0
class ExcelHandler(object):
    '''
    关于Excel表的操作
    '''
    oper_j = operate_json.OperateJson()
    con = Config.Config()

    def get_excel_data(self, case_desc):
        '''
        过滤excel中不必要的数据,当遇到特殊标签all,就全执行
        :param case_desc: 通过excel中的case_description来过滤用例
        :return:
        '''
        # 获取到book对象
        book = xlrd.open_workbook(Config.TEST_CASE_PATH)
        sheet = book.sheet_by_index(0)
        rows, cols = sheet.nrows, sheet.ncols
        l = []
        title = sheet.row_values(0)
        # 获取其他行
        for i in range(1, rows):
            #print(sheet.row_values(i))
            if case_desc in sheet.row_values(
                    i) or case_desc == 'all':  # 判定case_desc在第二行数据中
                l.append(dict(zip(title, sheet.row_values(i))))
        return l
コード例 #4
0
ファイル: operate_sql_al.py プロジェクト: Alwinwenzhe/Lp_edu
class OperateSqlAl(object):

    oj = operate_json.OperateJson()
    con = Config.Config()

    def __init__(self, envir):
        if 'ysy_test' == envir:  # 一生约测试
            self.dbhost = self.con.tysy_db_host
            self.dbport = int(self.con.tysy_db_port)
            self.dbname = self.con.tysy_db_name
            self.db_user = self.con.tysy_db_user
            self.pwd = self.con.tysy_db_pwd
        elif 'ysy_release' == envir or 'ysy_pro_release' == envir:  # 一生约正式
            self.dbhost = self.con.ysy_db_host
            self.dbport = int(self.con.ysy_db_port)
            self.dbname = self.con.ysy_db_name
            self.db_user = self.con.ysy_db_user
            self.pwd = self.con.ysy_db_pwd
        elif 'yhz_test' == envir:  # 雨花测试环境
            self.dbhost = self.con.ysy_db_host
            self.dbport = int(self.con.ysy_db_port)
            self.dbname = self.con.tysy_db_name
            self.db_user = self.con.tyhz_user
            self.pwd = self.con.tysy_db_pwd
        elif 'yhz_release' == envir:  # 雨花正式环境
            self.dbhost = self.con.ysy_db_host
            self.dbport = int(self.con.ysy_db_port)
            self.dbname = self.con.yhz_db_name
            self.db_user = self.con.ysy_db_user
            self.pwd = self.con.ysy_db_pwd
        elif 'ysy_o2o' == envir:  # 小猪正式环境--很多都和一生约正式相同
            self.dbhost = self.con.ysy_db_host
            self.dbport = int(self.con.ysy_db_port)
            self.dbname = self.con.db_name_o2o
            self.db_user = self.con.ysy_db_user
            self.pwd = self.con.ysy_db_pwd

    def re_sql(self, var_str):
        """
        处理str中包含了变量的sql
        :param str:可能包含了formate的字符串
        :return:不包含了formate的字符串
        """
        if 'format' in var_str:
            p1 = re.compile(r"[(](.*?)[')]", re.S)
            split_str = var_str.split('format')
            var_1 = re.findall(p1, split_str[1])
            #这里会对list中每个值进行判断
            var_1 = self.ut.circular_processing_data(var_1)
            # 注意这里只传递了第一个格式化值进来
            sql_resutl = split_str[0].format(*var_1)
            return sql_resutl
        else:
            return var_str

    def execute_sql(self, sql_str):
        try:
            db = pymysql.connect(host=self.dbhost,
                                 port=self.dbport,
                                 user=self.db_user,
                                 passwd=self.pwd,
                                 db=self.dbname,
                                 charset='utf8')
            cursor = db.cursor()  # 创建一个游标
            cursor.execute(sql_str)
            data = cursor.fetchone()
            data = self.bytes_to_str(data[0])
            return data
        except Exception:
            print('\033[1;33m"sql执行异常,请检查"\033[0m \n')
        finally:
            cursor.close()
            db.close()  # 关闭数据库

    def bytes_to_str(self, val1):
        if type(val1) == bytes:
            val1 = val1.decode(encoding='utf-8')
        return val1