python 接口测试多数据依赖该如何解决?

接口测试多数据依赖

依赖接口返回的数据:
{“REMARK_”:"",“ORDER_TYPE_”:“10”,“TARGET_CHARGE_ID_”:“849a34cef18f4b6cac5fbf1f5ee1f4c1”,“ORDER_MONEY_”:“4”,“ACCOUNT_NO_”:“176****6020”,“SERVICE_ID_”:“1”,“TRANSACTION_NO_”:“2019091022001452750557123890”,“ORDER_STATUS_”:“3”,“REFUNDS_REMARK_”:"",“SUBJECT_”:“钱包充值”,“CREATE_TIME_”:“2019-09-10 13:16:44”,“REFUNDS_ERR_CODE_”:"",“COUPON_ID_”:"",“CHARGE_ID_”:“ch_fLWPm5i5Ge90yP4SuDKq9WbP”,“SERVICE_CHARGE_”:“0”,“REFUNDS_ORDER_ID_”:"",“REFUNDS_ERR_TIME_”:"",“REFUNDS_FLAG_”:“0”,“ORDER_FLAG”:“1”,“ID_”:“cc0ff07ca65d4be28250372d1d672a51”,“CHARGE_CHANNEL_”:“alipay”,“USER_ID_”:“u01289891”,“REFUNDED_TIME_”:"",“APP_ID_”:“mtpff8e16797c53bb63”,“BEFORE_DIS_MONEY_”:"",“CHARGE_REMARK_”:"",“PAID_TIME_”:“2019-09-10 13:16:50”,“ORDER_EXTRA_”:"",“ORDER_NO_”:“u012898912019091013164410Cbw”,“BODY_”:“钱包充值”,“PRI_ID”:“1000004”}

请求的data数据如下:
{“accessToken”:"*******************",
“orderId”:"&",
“refundedTime”:"&",
“remark”:“接口测试”,
“userId”:"&"}

代码实现如下:

                if depend_case != None:
                    self.depend_data = DependentData(depend_case,token)
                    #查找被依赖的接口数据
                    rep = self.depend_data.run_dependent()
                    rep = json.loads(rep)
                    example = re.compile("&<(.*?)>")
                    # 在data里面查找&<>格式的数据,并输出到list b ,遍历list b并替换掉
                    b = re.findall(example,data)
                    for n in b:
                        value = self.operjson.dict_get(rep, n, None)
                        str = "&<%s>" % n
                        data = data.replace(str, value)

你可能感兴趣的:(测试,测试)