Beispiel #1
0
def change_caseid(caseid1, caseid2, i):
    TABLE_NAME = "cases_copy"
    opera_db = OperationDB()
    sql = "select case_id,post_action from {} where case_id>='{}' and case_id<='{}';".format(
        TABLE_NAME, caseid1, caseid2)
    data = opera_db.search_all(sql)
    print(data)
    for item in data:
        caseid = item.get("case_id")
        num = int(re.search("\d+(?=_)", caseid).group())
        num1 = num + i
        caseid_new = re.sub(str(num), str(num1), caseid)
        post_action = item.get("post_action")
        if post_action and "case_id" in post_action and (
                post_action.split("=")[1] >= caseid1
                and post_action.split("=")[1] <= caseid2):
            num2 = int(
                re.search("\d+(?=_)",
                          post_action.split("=")[1]).group())
            num3 = num2 + i
            post_action_new = re.sub(str(num2), str(num3), post_action)
        else:
            post_action_new = post_action
        sql1 = "update {} set case_id='{}',post_action='{}' where case_id='{}';".format(
            TABLE_NAME, caseid_new, post_action_new, caseid)
        opera_db.sql_DML(sql1)
Beispiel #2
0
 def get_expect_for_db(self):
     if self.db_data and self.db_data[settings.EXPECT_FOR_DB]:
         expect = self.db_data[settings.EXPECT_FOR_DB]
         # 如果有多个参数,比如前面是sql语句,后面是期望这个sql语句返回的结果
         expect_list = expect.split("|")
         expect_list[0] = self.replace_randnum_for_str(expect_list[0])
         db_and_sql = expect_list[0].split(">")
         if len(db_and_sql) == 2:
             db_name = db_and_sql[0]
             sql = db_and_sql[1]
         else:
             db_name = settings.DEV_DB_NAME
             sql = db_and_sql[0]
         # 从设备上把db文件拷贝下来,传过来的需要告知是查询哪张表,如果不传给个默认
         # print(settings.SQLITE_CMD.format(db_name,db_name,settings.win_ip))
         # do_telnet(settings.SQLITE_CMD.format(db_name,db_name,settings.win_ip))
         # 打开数据库连接
         # op_db = OperationDB("sqlite", db_name)
         op_db = OperationDB(settings.DB_TYPE, db_name)
         expect_list[0] = op_db.search_one(sql)
         if len(expect_list) == 2:
             # 如果查不到的就预期空值,比如删除了的
             if expect_list[1] == "None":
                 expect_list[1] = eval(expect_list[1])
             elif "{" in expect_list[1]:
                 if "##" in expect_list[1]:
                     # 如果里面有需要替换的动态变量,才去走替换函数,提高性能,否则每次不管有没有要替换的变量,都要去递归判断每个变量是否需要替换,接口比较多的话会耗时多
                     expect_list[1] = self.replace_randnum(
                         json.loads(expect_list[1]))
                 else:
                     expect_list[1] = json.loads(expect_list[1])
                 if "true" in json.dumps(expect_list[1]):
                     expect_list[1] = self.replace_true(expect_list[1])
         return expect_list
Beispiel #3
0
 def __init__(self, post_action, post_params, depend_case_id, url):
     self.db = OperationDB()
     self.url = url
     self.post_action = post_action
     self.post_params = post_params
     self.depend_case_id = depend_case_id
     self.logger = get_logger()
Beispiel #4
0
 def __init__(self, data):
     self.db = OperationDB()
     self.data = data
Beispiel #5
0
 def __init__(self):
     self.op_db = OperationDB()
     self.result = self.get_result()
Beispiel #6
0
 def __init__(self, data):
     self.db_data = data
     self.op_db = OperationDB()
     self.read_i = ReadIni()
Beispiel #7
0
    def replace_rand_param(self):
        pass

    def get_expext(self):
        return self.db_data and self.db_data[settings.EXPECT]

    def get_expect_for_db(self):
        expect = self.get_expext()
        if expect and "{" in expect:
            expect = json.loads(expect)
            if settings.EXPECT_SQL in expect:
                sql = expect[settings.EXPECT_SQL]
                expect = self.op_db.search_one(sql)
        return expect

    def get_result(self):
        return self.db_data and self.db_data[settings.RESULT]

    def write_result(self, sql, param):
        self.op_db.sql_DML(sql, param)


if __name__ == "__main__":
    db = OperationDB()
    sql = "select * from cases where case_id=%s"
    pa = ("qingguo_001", )
    data = db.search_one(sql, pa)
    d = DataConfig(data)
    r = d.get_header()
    print(r, type(r))
Beispiel #8
0
 def __init__(self, data):
     self.data = data
     self.get_field()
     self.op_db = OperationDB()
Beispiel #9
0
 def __init__(self, data):
     self.db_data = data
     self.op_db = OperationDB()
Beispiel #10
0
 def __init__(self):
     self.op_db = OperationDB()
     self.chrome_result = self.get_chrome_result()
     self.firefox_result = self.get_firefox_result()
     self.edge_result = self.get_edge_result()
Beispiel #11
0
 def __init__(self):
     self.op_db = OperationDB()
Beispiel #12
0
    def get_is_run(self):
        return self.db_data and self.db_data[settings.IS_RUN]

    def get_expext(self):
        return self.db_data and self.db_data[settings.EXPECT]

    def get_expect_method(self):
        return self.db_data and self.db_data[settings.EXPECT_METHOD]

    def get_expect_method_params(self):
        return self.db_data and self.db_data[
            settings.EXPECT_METHOD_PARAMS] and json.loads(
                self.db_data[settings.EXPECT_METHOD_PARAMS])

    def write_result(self, sql, param):
        self.op_db.sql_DML(sql, param)


if __name__ == "__main__":
    db = OperationDB(settings.DB_TYPE, settings.DB_USER, settings.DB_PASSWD,
                     settings.DB_HOST, settings.DB_PORT, settings.DB_NAME)
    sql = "select * from ui_cases where case_id=%s"
    pa = ("register_001", )
    data = db.search_one(sql, pa)
    d = DataConfig(data)
    r = d.get_edge_result()
    print(r)
    # sql1 = "update ui_cases set result=%s where case_id=%s"
    # para1 = ("pass","register_001")
    # d.write_result(sql1,para1)
Beispiel #13
0
 def get_verify_code(self, key):
     redis_db = OperationDB("redis")
     code = redis_db.search_one(key)
     read_i = ReadIni()
     code = json.loads(code).get("code")
     read_i.write_data(key.split(":")[0], code)