单独调取excle每行数据对支付接口进行测试:
import requests
from a.utils.get_excle_data import get_all_excle_data
from a.utils.md5_python import md5Python as md5
from a.utils.date_random import get_random
from a.utils.tools import del_null
from a.utils.date_random import get_random_param as get_unique
from a.log.logger import Logger
import json
from shop_center.utils.get_excle_path import get_excle_path
def pay(excle_file,sheet_name,row,auth_code=""):
# 获取接口的数据
excle_data = get_all_excle_data(excle_file, sheet_name, row)
url = excle_data['host'] + "/open/pay"
key = excle_data['key']
params = excle_data['params']
random = get_random()
outTradeNo = get_unique('otn')
if auth_code == "" :
# auth_code = input("please input authCode: ")
auth_code = input(
'[{} {} {}] \n {}'.format(row, excle_data['testCases'], params['totalAmount'], 'please input authCode:'))
params = {
"appId":params['appId'],
"merchantCode": params['merchantCode'],
"random":random,
"outTradeNo":outTradeNo,
"totalAmount":params['totalAmount'],
"authCode": auth_code,
"orderSource":params['orderSource'],
......
}
params = del_null(params)
params["sign"] = md5.md5_sign(params, key)
#接口请求
r = requests.post(url, data=params)
#返回接口的请求和返回信息
result = {
'req': params,
'res': r.json(),
'url': url,
'testCases': excle_data['testCases']
}
return result
if __name__ == '__main__':
log = Logger("info")
excle_file = get_excle_path()
sheet_name = 'pay_test'
# sheet_name = 'pay_hui'
# sheet_name = 'pay_online'
row = 2
# auth_code = input("please input authCode: ")
result = pay(excle_file, sheet_name, row)
log.info("请求地址为:{}".format(result['url']))
log.info("支付请求信息:" + str(json.dumps(result['req'], ensure_ascii=False)))
log.info("支付返回信息:" + str(json.dumps(result['res'], ensure_ascii=False)))
print('订单:{} {} {}'.format(result['req']['outTradeNo'],result['res']["msg"],result['res']['totalAmount']))
assert result['res']['code'] == "SUCCESS"
assert result['res']['msg'] == "支付成功"
assert result['res']['totalAmount'] == result['req']['totalAmount']
单独调取excle每行数据对订单查询接口进行测试:
import requests
from a.utils.get_excle_data import get_all_excle_data
from a.utils.md5_python import md5Python as md5
from a.utils.date_random import get_random
from a.utils.tools import del_null
from a.log.logger import Logger
import json
from a.utils.get_excle_path import get_excle_path
def query(excle_file,sheet_name,row,out_trade_no=""):
# 获取接口的数据
excle_data = get_all_excle_data(excle_file, sheet_name, row)
url = excle_data['host'] + "/open/pay/query"
key = excle_data['key']
params = excle_data['params']
random = get_random()
params = {
"appId":params['appId'],
"merchantCode": params['merchantCode'],
"random":random,
"outTradeNo":out_trade_no,
......
}
params = del_null(params)
params["sign"] = md5.md5_sign(params, key)
# 接口请求
r = requests.post(url, data=params)
# 返回接口的请求和返回信息
result = {
'req': params,
'res': r.json(),
'url': url
}
return result
if __name__ == '__main__':
log = Logger("info")
excle_file = get_excle_path()
sheet_name = 'pay_test'
# sheet_name = 'pay_hui'
# sheet_name = 'pay_online'
row = 2
out_trade_no = 'otn20200925105536946672'
result = query(excle_file,sheet_name,row,out_trade_no)
log.info("请求地址为:" + result['url'])
log.info("支付查询请求信息:" + str(json.dumps(result['req'], ensure_ascii=False)))
log.info("支付查询返回信息:" + str(json.dumps(result['res'], ensure_ascii=False)))
assert result['res']['code'] == "SUCCESS"
assert result['res']['msg'] == "订单已支付"
# print(result['res']["msg"])
单独调取excle每行数据对退款接口进行测试:
import requests
from a.utils.get_excle_path import get_excle_path
from a.utils.get_excle_data import get_all_excle_data
from a.utils.md5_python import md5Python as md5
from a.utils.date_random import get_random
from a.utils.date_random import get_random_param as get_unique
from a.utils.tools import del_null
from a.log.logger import Logger
import json
def refund(excle_file,sheet_name,row,out_trade_no=""):
# 获取接口的数据
excle_data = get_all_excle_data(excle_file, sheet_name, row)
url = excle_data['host'] + "/open/refund"
key = excle_data['key']
params = excle_data['params']
random = get_random()
refundNo = get_unique('orn')
params = {
"appId":params['appId'],
"merchantCode": params['merchantCode'],
"random":random,
"outTradeNo":out_trade_no,
"refundNo":refundNo,
......
}
params = del_null(params)
params["sign"] = md5.md5_sign(params, key)
# 接口请求
r = requests.post(url, data=params)
# 返回接口的请求和返回信息
result = {
'req': params,
'res': r.json(),
'url': url
}
return result
if __name__ == '__main__':
log = Logger("info")
excle_file = get_excle_path()
sheet_name = 'pay_test'
# sheet_name = 'pay_hui'
# sheet_name = 'pay_online'
row = 2
out_trade_no = ['otn20201012151219557311']
for i in range(len(out_trade_no)):
result = refund(excle_file,sheet_name,row,out_trade_no[i])
log.info("请求地址为:" + result['url'])
log.info("退款请求信息:" + str(json.dumps(result['req'], ensure_ascii=False)))
log.info("退款返回信息:" + str(json.dumps(result['res'], ensure_ascii=False)))
log.info('订单:{} 退款订单:{} {} {}'.format(result['req']['outTradeNo'],
result['res']["refundNo"],result['res']["msg"], result['res']['refundAmount']))
assert result['res']['code'] == "SUCCESS"
assert result['res']['msg'] == "退款成功"
单独调取excle每行数据对退款查询接口进行测试:
import requests
from a.utils.get_excle_data import get_all_excle_data
from a.utils.md5_python import md5Python as md5
from a.utils.date_random import get_random
from a.utils.tools import del_null
from a.log.logger import Logger
from a.utils.get_excle_path import get_excle_path
def refund_query(excle_file,sheet_name,row,refund_no=""):
# 获取接口的数据
excle_data = get_all_excle_data(excle_file, sheet_name, row)
url = excle_data['host'] + "/open/refund/query"
key = excle_data['key']
params = excle_data['params']
random = get_random()
params = {
"appId":params['appId'],
"merchantCode": params['merchantCode'],
"random":random,
"refundNo":refund_no,
"operatorId":params['operatorId']
}
params = del_null(params)
params["sign"] = md5.md5_sign(params, key)
# 接口请求
r = requests.post(url, data=params)
# 返回接口的请求和返回信息
result = {
'req': params,
'res': r.json(),
'url': url
}
return result
if __name__ == '__main__':
log = Logger("info")
excle_file = get_excle_path()
sheet_name = 'pay_test'
# sheet_name = 'pay_hui'
# sheet_name = 'pay_online'
row = 2
refund_no = 'orn20200925112233200605'
result = refund_query(excle_file,sheet_name,row,refund_no)
log.info("请求地址为:" + result['url'])
log.info("退款查询请求信息:" + str(result['req']))
log.info("退款查询返回信息:" + str(result['res']))
assert result['res']['code'] == "SUCCESS"
assert result['res']['msg'] == "退款成功"
print(result['res']["msg"])
串联支付-查询-退款-退款查询-调取excle每行数据测试
from a.utils.get_excle_path import get_excle_path
from a.shop.pay_all.pay import pay
from a.shop.pay_all.query import query
from a.shop.pay_all.refund import refund
from a.shop.pay_all.refund_query import refund_query
from a.log.logger import Logger
import json
import time
if __name__ == '__main__':
log = Logger("info")
excle_file = get_excle_path()
sheet_name = 'pay_test'
# sheet_name = 'pay_hui'
# sheet_name = 'pay_online'
for row in range(1,3):# 执行第几行的用例
# 支付
pay_result = pay(excle_file,sheet_name,row)
time.sleep(5)
out_trade_no = pay_result['req']["outTradeNo"]
log.info("请求地址:" + str(pay_result['url']))
log.info("支付请求信息:" + str(json.dumps(pay_result['req'], ensure_ascii=False)))
log.info("支付返回信息:" + str(json.dumps(pay_result['res'], ensure_ascii=False)))
log.info('{} [{}] [订单:{} {} 订单金额:{} 实收金额:{} 优惠金额:{}]'.format(
row,pay_result['testCases'],out_trade_no,pay_result['res']["msg"],
pay_result['res']['totalAmount'],pay_result['res']['receiptAmount'],pay_result['res']['discountAmount']))
assert pay_result['res']['code'] == "SUCCESS"
assert pay_result['res']['msg'] == "支付成功"
assert pay_result['res']['totalAmount'] == pay_result['req']['totalAmount']
#支付检测
# outTradeNo = 'otn20191219210135705'
result_query = query(excle_file, sheet_name, row, out_trade_no)
time.sleep(3)
log.info("支付查询请求信息:" + str(json.dumps(result_query['req'], ensure_ascii=False)))
log.info("支付查询返回信息:" + str(json.dumps(result_query['res'], ensure_ascii=False)))
assert result_query['res']['code'] == "SUCCESS"
assert result_query['res']['msg'] == "订单已支付"
#退款
result_refund = refund(excle_file, sheet_name, row, out_trade_no)
time.sleep(5)
log.info("退款请求信息:" + str(json.dumps(result_refund['req'], ensure_ascii=False)))
log.info("退款返回信息:" + str(json.dumps(result_refund['res'], ensure_ascii=False)))
refund_no = result_refund['req']["refundNo"]
assert result_refund['res']['code'] == "SUCCESS"
assert result_refund['res']['msg'] == "退款成功"
#退款检测
result_refund_query = refund_query(excle_file, sheet_name, row, refund_no)
time.sleep(3)
log.info("退款查询请求信息:" + str(json.dumps(result_refund_query['req'], ensure_ascii=False)))
log.info("退款查询返回信息:" + str(json.dumps(result_refund_query['res'], ensure_ascii=False)))
log.info(result_refund_query['res']["msg"])
assert result_refund_query['res']['code'] == "SUCCESS"
assert result_refund_query['res']['msg'] == "退款成功"
网友评论