Ejemplo n.º 1
0
 def setup_class(self):
     '''执行用例前执行一次'''
     excelhandler = ExcelHandler()
     table = excelhandler.table_name()
     mysql = MysqlHandler()
     mysql.create_table(table)  #创建依赖数据表
     run = NotRunBeDependCase()
     run.not_run_be_depend_case()  # 执行有被依赖但是不执行的用例
 def savedependvalue(self, depend_data_key, response):
     excelhandler = ExcelHandler()
     table = excelhandler.table_name()
     getvalue = GetValue()
     depend_value = getvalue.get_json_value_by_key(response,
                                                   depend_data_key)
     for value in depend_value:
         sql = MysqlHandler()
         # 把每一个依赖key,value保存到数据库
         # print(table, depend_data_key, value)
         sql.insert_data(table, depend_data_key, value)
Ejemplo n.º 3
0
 def getparam(self,case_depend_key,param):
     excelhandler = ExcelHandler()
     table = excelhandler.table_name()
     mysql = MysqlHandler()
     # 获取数据库的依赖值
     repl = mysql.select_table('value', table, case_depend_key)
     pattern = '<' + case_depend_key + '>'
     # repl替换掉string中被pattern匹配的字符, count表示最大替换次数,flags表示正则表达式的常量
     param = str(param)
     # print(pattern,repl,param)
     value = re.sub(pattern, repl, param, count=1, flags=re.IGNORECASE)
     param = eval(value)
     return param
Ejemplo n.º 4
0
class NotRunBeDependCase(object):
    '''
    1、执行被依赖但不执行的case
    2、获取依赖的值
    3、以key,value的形式保存到数据库
    '''
    def __init__(self):
        self.excelhandler = ExcelHandler()
        self.dependhandler = DependHandler()
        self.getvalue = GetValue()

    def not_run_be_depend_case(self):
        #获取所有的case
        excel_data = self.excelhandler.get_all_excel_data
        #获取插入表
        table = self.excelhandler.table_name()
        mysql = MysqlHandler()
        mysql.create_table(table)
        # 循环遍历每一条case
        for case in excel_data:
            is_run = case['case_run'].upper()
            if case['case_response_key'] != '' and is_run != 'YES':
                url = case['case_url']
                method = case['case_method']
                type = case['params_type']
                data = case['case_params']
                #执行被依赖用例
                response = self.dependhandler.send_depend_request(
                    url, method, type, data)
                depend_key = case['case_response_key']
                depend_value = self.getvalue.get_json_value_by_key(
                    response, depend_key)
                for value in depend_value:
                    sql = MysqlHandler()
                    # 把每一个依赖key,value保存到数据库
                    sql.insert_data(table, depend_key, value)