1 #coding:utf-8
2 importsys3 importjson4 sys.path.append(‘C:/Users/lxz/Desktop/InterFace_JIA‘)5 from tool.operation_excel importOperationExcel6 from base.runmethod importRunMethod7 from operation_data.get_data importGetData8 from jsonpath_rw importjsonpath,parse9 classDependdentData:10 def __init__(self,case_id):11 self.case_id =case_id12 self.opera_excel =OperationExcel()13 self.data =GetData()14
15 #通过case_id去获取该case_id的整行数据
16 defget_case_line_data(self):17 rows_data =self.opera_excel.get_rows_data(self.case_id)18 returnrows_data19
20 #执行依赖测试,获取结果
21 defrun_dependent(self):22 run_method =RunMethod()23 row_num =self.opera_excel.get_row_num(self.case_id)24 request_data =self.data.get_data_for_json(row_num)25 #header = self.data.is_header(row_num)
26 method =self.data.get_request_method(row_num)27 url =self.data.get_request_url(row_num)28 res =run_method.run_main(method,url,request_data)29 returnjson.loads(res)30
31 #根据依赖的key去获取执行依赖测试case的响应,然后返回
32 defget_data_for_key(self,row):33 depend_data =self.data.get_depend_key(row)34 response_data =self.run_dependent()35 json_exe =parse(depend_data)36 madle =json_exe.find(response_data)37 return [math.value for math inmadle][0]38
39 if __name__ == ‘__main__‘:40 order ={41 "data": {42 "_input_charset": "utf-8",43 "body": "京东订单-1710141907182334",44 "it_b_pay": "1d",45 "notify_url": "http://order.imooc.com/pay/notifyalipay",46 "out_trade_no": "1710141907182334",47 "partner": "2088002966755334",48 "payment_type": "1",49 "seller_id": "yangyan01@tcl.com",50 "service": "mobile.securitypay.pay",51 "sign": "kZBV53KuiUf5HIrVLBCcBpWDg%2FnzO%2BtyEnBqgVYwwBtDU66Xk8VQUTbVOqDjrNymCupkVhlI%2BkFZq1jOr8C554KsZ7Gk7orC9dDbQl
pr%2BaMmdjO30JBgjqjj4mmM%2Flphy9Xwr0Xrv46uSkDKdlQqLDdGAOP7YwOM2dSLyUQX%2Bo4%3D",52 "sign_type": "RSA",53 "string": "_input_charset=utf-8&body=京东订单-1710141907182334&it_b_pay=1d¬ify_url=http://order.imooc.com/pay/
notifyalipay&out_trade_no=1710141907182334&partner=2088002966755334&payment_type=1&seller_id=yangyan01@
tcl.com&service=mobile.securitypay.pay&subject=京东订单-1710141907182334&total_fee=299&sign=kZBV53KuiUf5H
IrVLBCcBpWDg%2FnzO%2BtyEnBqgVYwwBtDU66Xk8VQUTbVOqDjrNymCupkVhlI%2BkFZq1jOr8C554KsZ7Gk7orC9dDbQlpr%2BaMmdjO30
JBgjqjj4mmM%2Flphy9Xwr0Xrv46uSkDKdlQqLDdGAOP7YwOM2dSLyUQX%2Bo4%3D&sign_type=RSA",54 "subject": "京东订单-1710141907182334",55 "total_fee": 299
56 },57 "errorCode": 1000,58 "errorDesc": "成功",59 "status": 1,60 "timestamp": 1507979239100
61 }62 res = "data.out_trade_no"
63 json_exe =parse(res)64 madle =json_exe.find(order)65 print [math.value for math in madle][0]