other_func.py 1.2 KB
# @Time     :2019/11/26 11:23
# @Author   :dengyuting
# @File     :login_func.py
import json


##每次执行自动化测试前,清空该文件,该文件用于批量支付时传orderids
def setup_hook_clean_orderid():
    try:
        with open('config/orderid.csv', 'w') as f:
            f.seek(0)
            f.truncate()
    except Exception as e:
        print('清空失败', e)


def teardown_hook_get_orderid(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        orderid =jsondata['data']['id']
    try:
        # 保存token到文件
        with open('config/orderid.csv','a+') as f:
            f.write(str(orderid)+',')
            print('写入成功,orderid:{}'.format(orderid))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return orderid


def get_orderids():
    try:
        with open('config/orderid.csv','r') as f:
            orderids = f.read()
            print('读取orderids成功:{}'.format(orderids))
            f.close()
    except Exception as e:
        print('读取失败', e)
    orderid = orderids.split(',')
    orderid.pop(-1)
    return orderid