コード例 #1
0
class GetData:
    def __init__(self):
        self.operation_excel = OperationExcel()
        self.get_headers_cookies = GetHeadersCookies()
        self.get_config = ReadConfig()

    def get_sheet_names(self):
        """获取当前工作簿中所有工作表的名称"""
        return self.operation_excel.get_sheet_names()

    def get_sheet_data(self, sheet_name):
        """通过sheet页名称读取对应sheet页的数据"""
        return self.operation_excel.get_sheet_data(sheet_name)

    def get_sheet_lines(self):
        """获取当前sheet页的总行数"""
        return self.operation_excel.get_sheet_lines()

    def get_json_file_name(self, sheet_name):
        """获取json文件名称"""
        sheet_name = "../test_data/json_data/" + sheet_name + ".json"
        return sheet_name

    def get_save_result_path(self):
        '''获取结果文件路径'''
        return self.operation_excel.save_result_path

    def get_is_run(self, x):
        """获取case是否运行"""
        flag = None
        y = data_conf.get_run()
        run_value = self.operation_excel.get_cell_value(x, y)
        if run_value.lower() == 'yes':
            flag = True
        else:
            flag = False
        return flag

    def get_is_header(self, x):
        """是否携带headers"""
        y = data_conf.get_request_header()
        header = self.operation_excel.get_cell_value(x, y)

        if header == 'yes':
            return self.get_headers_cookies.get_headers_value()
        else:
            return None

    def get_is_cookie(self, x):
        """是否携带cookies"""
        y = data_conf.get_request_cookie()
        cookie = self.operation_excel.get_cell_value(x, y)
        if cookie == 'yes':
            return self.get_headers_cookies.get_cookies_value()
        return None

    def get_request_method(self, x):
        """获取请求方法"""
        y = data_conf.get_request_method()
        request_method = self.operation_excel.get_cell_value(x, y)
        return request_method

    def get_request_url(self, x):
        """获取请求地址"""
        y = data_conf.get_url()
        request_url = self.operation_excel.get_cell_value(x, y)
        base_url = self.get_config.get_http_config_var('baseurl')
        request_url = base_url + request_url
        return request_url

    def get_request_data(self, sheet_name, x):
        """获取请求数据"""
        y = data_conf.get_request_data()
        request_data_key = self.operation_excel.get_cell_value(x, y)
        if request_data_key == '':
            return None
        else:
            request_data = self.__get_data_for_json(sheet_name,
                                                    request_data_key)
            return request_data

    def __get_data_for_json(self, sheet_name, request_data_key):
        """通过excel中关键字去获取json数据"""
        sheetName = self.get_json_file_name(sheet_name)
        op_json = OperationJson(file_path=sheetName)
        data = op_json.get_key_words(request_data_key)
        return data

    def get_expect_data(self, x):
        """获取预期结果数据"""
        y = data_conf.get_expect_result()
        expect_data = self.operation_excel.get_cell_value(x, y)
        if expect_data == '':
            return None
        else:
            return string_to_eval(x, y, expect_data)

    def get_module_name(self, x):
        """获取模块名称"""
        y = data_conf.get_name()
        module_name = self.operation_excel.get_cell_value(x, y)
        return module_name

    def write_real_result(self, sheet_name, row, value):
        """写测试结果到excel"""
        y = data_conf.get_real_results()
        self.operation_excel.write_value(sheet_name, row, y, value)

    def get_is_case_depend(self, x):
        """判断是否有case依赖"""
        y = data_conf.get_case_depend()
        case_depend = self.operation_excel.get_cell_value(x, y)
        if case_depend == "":
            return None
        else:
            return string_to_eval(x, y, case_depend)

    def get_depend_data(self, x):
        """获取响应结果中的依赖字段"""
        y = data_conf.get_data_depend()
        data_depend = self.operation_excel.get_cell_value(x, y)
        if data_depend == "":
            return None
        else:
            return string_to_eval(x, y, data_depend)

    def get_depend_filed(self, x):
        """获取数据依赖字段"""
        y = data_conf.get_filed_depend()
        filed_depend = self.operation_excel.get_cell_value(x, y)
        if filed_depend == "":
            return None
        else:
            return string_to_eval(x, y, filed_depend)
コード例 #2
0
ファイル: get_data.py プロジェクト: liuzouzou/api_test_report
class GetData(object):

    def __init__(self):
        self.opera_excel = OperationExcel()
        self.sheet = self.opera_excel.get_data()

    '''获取excel的行数,就是我们的case个数'''

    def get_case_lines(self):
        try:
            return self.opera_excel.get_lines()
        except Exception as e:
            logging.info("错误为:", e)

    '''获取是否执行'''

    def get_is_run(self, row):
        try:
            flag = None
            col = get_run()
            run_model = self.opera_excel.get_cell_value(row, col)
            if run_model == 'y':
                flag = True
            else:
                flag = False
            return flag
        except Exception as e:
            logging.info("错误为:", e)

    '''获取接口描述'''

    def get_api_msg(self, row):
        try:
            col = get_request_name()
            api_msg = self.opera_excel.get_cell_value(row, col)
            return api_msg
        except Exception as e:
            logging.info("错误为:", e)

    '''获取接口名称'''

    def get_api_name(self, row):
        try:
            col = get_api_name()
            api_name = self.opera_excel.get_cell_value(row, col)
            return api_name
        except Exception as e:
            logging.info("错误为:", e)

    '''是否携带header'''

    def get_request_headers(self, row):
        try:
            col = get_header()
            header = self.opera_excel.get_cell_value(row, col)
            if header == '':
                return None
            return header
        except Exception as e:
            logging.info("错误为:", e)

    '''是否有header'''

    def is_header(self, row):
        try:
            col = get_header()
            header = self.opera_excel.get_cell_value(row, col)

            if header != 'n':
                header = json.loads(header)
                return header
                # return self.opera_excel.get_cell_value(row,col)
            elif header == 'w':
                return 'w'
            else:
                return None
        except Exception as e:
            logging.info("错误为:", e)

    '''获取请求方式'''

    def get_request_method(self, row):
        try:
            col = get_run_way()
            request_method = self.opera_excel.get_cell_value(row, col)
            return request_method
        except Exception as e:
            logging.info("错误为:", e)

    '''获取url'''

    def get_request_url(self, row):
        try:
            col = get_url()
            url = self.opera_excel.get_cell_value(row, col)
            return url
        except Exception as e:
            logging.info("错误为:", e)

    '''请求数据'''

    def get_request_data(self, row):
        try:
            col = get_data()
            data = self.opera_excel.get_cell_value(row, col)
            if data == '':
                return None
            return data
        except Exception as e:
            logging.info("错误为:", e)

    '''通过获取关键字拿到data数据'''

    def get_data_for_json(self, row):
        try:
            opera_json = OperationJson()
            request_data = opera_json.get_data(self.get_request_data(row))
            return request_data
        except Exception as e:
            logging.info("错误为:", e)

    '''获取要提取的字段的值'''

    def get_depend_value(self, row):
        try:
            col = get_depend_value()
            depend_value = self.opera_excel.get_cell_value(row, col)
            if depend_value == '':
                return None
            return depend_value
        except Exception as e:
            logging.info("错误为:", e)

    '''获取预期结果'''

    def get_expect_data(self, row):
        try:
            col = get_expect()
            expect = self.opera_excel.get_cell_value(row, col)
            if expect == '':
                return None
            return expect
        except Exception as e:
            logging.info("错误为:", e)

    '''获取http状态码'''

    def get_http_code_data(self, row):
        try:
            col = get_http_code()
            http_code = self.opera_excel.get_cell_value(row, col)
            return http_code
        except Exception as e:
            logging.info("错误为:", e)

    '''获取待替换的值'''

    def get_waiting_replace_key(self, row):
        try:
            col = get_waiting_replace_key()
            wait_rep_key = self.opera_excel.get_cell_value(row, col)
            if wait_rep_key == '':
                return None
            return wait_rep_key
        except Exception as e:
            logging.info('错误为:', e)

    '''获取实际替换的值'''

    def get_actual_replace_key(self, row):
        try:
            col = get_actual_replace_key()
            act_rep_key = self.opera_excel.get_cell_value(row, col)
            if act_rep_key == '':
                return None
            return act_rep_key
        except Exception as e:
            logging.info('错误为:', e)

    '''写入数据'''

    def write_result(self, row, value):
        try:
            col = get_result()
            self.opera_excel.write_value(sheet=self.sheet, content=value, rowNo=row, colsNo=col)
        except Exception as e:
            logging.info("错误为:", e)

    '''获取依赖返回数据的key'''

    def get_depend_key(self, row):
        try:
            col = get_data_depend()
            depent_key = self.opera_excel.get_cell_value(row, col)
            if depent_key == "":
                return None
            else:
                return depent_key
        except Exception as e:
            logging.info("错误为:", e)

    def is_depend(self, row):  # 是否有依赖
        try:
            col = get_case_depend()
            depend_case_id = self.opera_excel.get_cell_value(row, col)
            if depend_case_id == "":
                return None
            else:
                return depend_case_id
        except Exception as e:
            logging.info("错误为:", e)

    '''获取数据依赖字段'''

    def get_depend_field(self, row):
        try:
            col = get_field_depend()
            data = self.opera_excel.get_cell_value(row, col)
            if data == "":
                return None
            else:
                return data
        except Exception as e:
            logging.info("错误为:", e)

    '''获取请求方式'''

    def get_set_key(self, row):
        try:
            col = get_set_key()
            request_method = self.opera_excel.get_cell_value(row, col)
            return request_method
        except Exception as e:
            logging.info("错误为:", e)
コード例 #3
0
ファイル: get_data.py プロジェクト: leelr1952/TestInterface
class GetData(object):
    def __init__(self, filename=None, sheet_id=None):
        self.opera_excel = OperationExcel(filename, sheet_id)

    def get_case_lines(self):
        return self.opera_excel.get_lines()

    def get_is_run(self, row):
        flag = None
        col = data_config.global_val.get_run()
        run_model = self.opera_excel.get_cell_value(row, int(col))
        if run_model == 'yes':
            flag = True
        else:
            flag = False
        return flag

    def is_cookie(self, row):
        col = data_config.global_val.get_cookie()
        cookie = self.opera_excel.get_cell_value(row, int(col))
        return cookie

    def is_header(self, row):
        col = data_config.global_val.get_header()
        header = self.opera_excel.get_cell_value(row, int(col))
        if header == 'yes':
            return data_config.global_val.get_header_value()
        else:
            return None

    def get_request_method(self, row):
        col = data_config.global_val.get_request_way()
        request_method = self.opera_excel.get_cell_value(row, int(col))
        return request_method

    def get_url(self, row):
        col = data_config.global_val.get_url()
        url = self.opera_excel.get_cell_value(row, int(col))
        return url

    def get_request_data(self, row):
        col = data_config.global_val.get_data()
        data = self.opera_excel.get_cell_value(row, int(col))
        if data == '':
            return None
        else:
            return data

    def get_data_for_json(self, row):
        self.opera_json = OperationJson()
        data_json = self.opera_json.get_data(self.get_request_data(row))
        return data_json

    def get_expect(self, row):
        col = data_config.global_val.get_expect()
        expect = self.opera_excel.get_cell_value(row, int(col))
        if expect == '':
            return None
        else:
            return expect

    def write_result(self, row, value):
        col = data_config.global_val.get_result()
        self.opera_excel.write_value(row, int(col), value)

    def get_data_depend(self, row):
        col = data_config.global_val.get_data_depend()
        data_depend = self.opera_excel.get_cell_value(row, int(col))
        if data_depend == "":
            return None
        else:
            return data_depend

    def is_depend(self, row):
        col = data_config.global_val.get_case_depend()
        case_depend = self.opera_excel.get_cell_value(row, int(col))
        if case_depend is not None:
            return case_depend
        else:
            return None

    def get_field_depend(self, row):
        col = data_config.global_val.get_field_depend()
        field_depend = self.opera_excel.get_cell_value(row, int(col))
        if field_depend is not None:
            return field_depend
        else:
            return None
コード例 #4
0
class GetData:
    def __init__(self):
        self.data = OperationExcel()
        self.dataconfig = GlobalVar()

    #获取总行数
    def get_case_lines(self):
        return self.data.get_rows()

    #获取是否执行case
    def get_is_run(self, row):
        flag = None
        col = self.dataconfig.get_run()
        runvalue = self.data.get_value(row, int(col))
        if runvalue == "yes":
            flag = True
        else:
            flag = False
        return flag

    # 获取获取header关键词
    def get_req_header(self, row):
        col = self.dataconfig.get_header()
        headervalue = self.data.get_value(row, int(col))
        if headervalue == "":
            return None
        return headervalue
        # if headervalue == "yes":
        #     return self.dataconfig.get_header_value()
        # else:
        #     return None

    # 根据关键词获取请求header的json内容
    def get_header_for_json(self, row):
        if self.get_req_header(row) != None:
            for_json = OperationJson(filename="../dataconfig/header.json")
            req_header = for_json.get_data(self.get_req_header(row))
            return req_header
        else:
            return None

    #获取是否获取cookie
    def get_is_cookie(self, row):
        col = self.dataconfig.get_cookies()
        cookievalue = self.data.get_value(row, int(col))
        if cookievalue == "write":
            return cookievalue
        elif cookievalue == "yes":
            self.getcookie = GetCookie()
            return self.getcookie.read_data()  #读取cookie
        else:
            return None

    #获取请求方式
    def get_request_method(self, row):
        col = self.dataconfig.get_method()
        req_methods = self.data.get_value(row, int(col))
        return req_methods

    #获取请求url
    def get_request_url(self, row):
        col = self.dataconfig.get_url()
        req_url = self.data.get_value(row, int(col))
        return req_url

    #获取请求数据的josn关键词
    def get_request_data(self, row):
        col = self.dataconfig.get_data()
        req_data = self.data.get_value(row, int(col))
        if req_data == "":
            return None
        return req_data

    #根据关键词获取请求数据的json内容
    def get_data_for_json(self, row):
        ecl_data = self.get_request_data(row)
        if self.get_request_data(row) != None:
            datas = ecl_data.split(":")
            if len(datas) > 1:
                for_json = OperationJson("../dataconfig/" + datas[0] + ".json")
                req_data = for_json.get_data(datas[1])
                return req_data
            else:
                print("请求数据格式不对!格式必须为 filename:jsonname")
                return None
        else:
            return None

    #获取预期结果
    def get_except_val(self, row):
        col = self.dataconfig.get_except()
        req_except = self.data.get_value(row, int(col))
        if req_except == "":
            return None
        return req_except

    #获取返回响应的依赖数据的key
    def get_depend_key(self, row):
        col = int(self.dataconfig.get_data_depend())  #获取列
        depend_key = self.data.get_value(row, col)
        if depend_key == "":
            return None
        else:
            return depend_key

    #判断是否有case依赖 获取依赖的case
    def is_depend(self, row):
        col = int(self.dataconfig.get_case_depend())  # 获取列
        depend_case_id = self.data.get_value(row, col)
        if depend_case_id == "":
            return None
        else:
            return depend_case_id

    #  获取请求数据的依赖key
    def get_depend(self, row):
        col = int(self.dataconfig.get_field_depend())  # 获取列
        data = self.data.get_value(row, col)
        if data == "":
            return None
        else:
            return data

    #  获取请求数据的依赖key
    def get_header_depend(self, row):
        col = int(self.dataconfig.get_header_depend())  # 获取列
        headers = self.data.get_value(row, col)
        if headers == "":
            return None
        else:
            return headers

    #写入实际结果
    def write_result(self, row, value):
        col = int(self.dataconfig.get_result())
        self.data.write_value(row, col, value)

    # 写入更新时间
    def write_update_time(self, row, value):
        col = int(self.dataconfig.get_update_time())
        self.data.write_value(row, col, value)

    #获取请求延迟时间 毫秒
    def get_delaytime_mm(self, row):
        col = int(self.dataconfig.get_delaytime())
        delayvalue = self.data.get_value(row, int(col))
        if delayvalue == "":
            return None
        else:
            return delayvalue

    #获取短信验证码
    def get_sms_value(self, cellphone):
        sql = "select code from driver_oauth where cellphone=" + cellphone
        self.dbs = ConnectDb()
        self.dbs.get_sms_db()
        sms = self.dbs.get_data_one(sql)
        print(sms)
        return sms
コード例 #5
0
class GerData:

    def __init__(self):
        self.opera_excel = OperationExcel()

    #去获取excel行数,就是我们的case个数
    def get_case_lines(self):
        return self.opera_excel.get_lines()


    #判断是否执行
    def get_is_run(self,row):
        flag = None
        col = int(data_config.get_run())
        run_model =self.opera_excel.get_cell_velue(row,col)
        if run_model == 'yes':
            return True
        else:
            return False
        return flag

    #判断是否携带header
    def is_header(self,row):
        col = int(data_config.get_header())
        header = self.opera_excel.get_cell_velue(row,col)
        if header == 'yes':
            return data_config.get_header_value()
        else:
            return None

    #获取请求方式
    def get_request_method(self,row):
        col = int(data_config.get_run_way())
        request_method = self.opera_excel.get_cell_velue(row,col)
        return request_method

    #获取url
    def get_request_url(self,row):
        col = int(data_config.get_url())
        url = self.opera_excel.get_cell_velue(row,col)
        return url

    #获取请求数据
    def get_request_data(self,row):
        col = int(data_config.get_data())
        data = self.opera_excel.get_cell_velue(row,col)
        if data == '':
            return None
        return data

    #通过关键字拿到data数据
    def get_data_for_json(self,row):
        opera_json = OperetionJson()
        request_data = opera_json.get_data(self.get_request_data(row))
        return request_data


    #获取预期结果
    def get_expect_data(self,row):
        col = int(data_config.get_expect())
        expect = self.opera_excel.get_cell_velue(row,col)
        #print(expect)
        if expect == '':
            return None
        return expect

    #获取实际结果
    def write_result(self,row,value):
        col = int(data_config.get_result())
        self.opera_excel.write_value(row,col,value)

    #获取依赖数据的key
    def get_depend_key(self,row):
        col = int(data_config.get_data_depend())
        depent_key = self.opera_excel.get_cell_velue(row,col)
        if depent_key == '':
            return None
        else:
            print("依赖的key:",depent_key)
            return depent_key

    #判断是否有case依赖
    def is_depend(self,row):
        col = int(data_config.get_case_depend())
        depend_case_id = self.opera_excel.get_cell_velue(row,col)
        if depend_case_id == "":
            return None
        else:
            print("依赖的caseid:",depend_case_id)
            return depend_case_id

    #获取数据依赖字段
    def get_depend_field(self,row):
        col = int(data_config.get_field_depend())
        depend_data = self.opera_excel.get_cell_velue(row,col)
        if depend_data == "":
            return None
        else:
            print('依赖的字段:',depend_data)
            return depend_data