mirror of https://gitee.com/a529548204/apitest.git
readme增加更新记录
This commit is contained in:
parent
e5a7628baf
commit
82adedf50d
29
README.md
29
README.md
|
@ -9,6 +9,7 @@ QQ 529548204
|
|||
如果有问题请联系我 大家共同学习共同进步~
|
||||
|
||||
# 更新日志
|
||||
2022年6月7日 更新 取消config中http类型 改为yaml数据内
|
||||
2022年5月30日 更新 YAML读取时间格式datetime数据后 json处理方式
|
||||
2022年5月20日 更新增加jenkins持续集成说明配置方法等
|
||||
2022年5月17日 更新增加xml参数处理,增加自定义加密方式(加密规则需要自己写 需要一定编码能力)
|
||||
|
@ -116,14 +117,24 @@ QQ 529548204
|
|||
```yaml
|
||||
relevance:
|
||||
response:
|
||||
- relCaseName: tradeAdd # 其他testcase的ID
|
||||
relCaseNum: 1 # 关联的case数组里 第几条数据
|
||||
value: $.id # 当前返回结果的jsonpath
|
||||
name: tradeId # 关联值名称
|
||||
- relCaseName: tradeAdd2 # 其他testcase的ID
|
||||
relCaseNum: 2 # 关联的case数组里 第几条数据
|
||||
value: $.id # 当前返回结果的jsonpath
|
||||
name: tradeId2 # 关联值名称
|
||||
- relCaseName: shangchuan # 其他testcase的ID
|
||||
relCaseNum: 1 # 关联的case数组里 第几条数据
|
||||
reldata:
|
||||
- value: $.data.fileName # 当前返回结果的jsonpath
|
||||
name: fileName # 关联值名称
|
||||
- value: $.data.policy # 当前返回结果的jsonpath
|
||||
name: policy # 关联值名称
|
||||
- value: $.data.signature # 当前返回结果的jsonpath
|
||||
name: signature # 关联值名称
|
||||
- relCaseName: tradeAdd2 # 其他testcase的ID
|
||||
relCaseNum: 2 # 关联的case数组里 第几条数据
|
||||
reldata:
|
||||
- value: $.data.fileName # 当前返回结果的jsonpath
|
||||
name: fileName # 关联值名称
|
||||
- value: $.data.policy # 当前返回结果的jsonpath
|
||||
name: policy # 关联值名称
|
||||
- value: $.data.signature # 当前返回结果的jsonpath
|
||||
name: signature # 关联值名称
|
||||
```
|
||||
### 1.3 参数介绍
|
||||
`file` : 通过case外关键字file判断是否需要上传文件 如果需要则格式为:`{上传文件的参数名:文件路径}`
|
||||
|
@ -271,6 +282,7 @@ login: # caseID **请务必唯一**
|
|||
file: true # bool值 true为需要文件的接口
|
||||
case:
|
||||
- info: "用户名登录-成功" # 用例信息
|
||||
http: https # http
|
||||
host: 'host' # config.ini里面 请求host的key
|
||||
address: '/v1/apps/$url(region_id)$/' # $url(region_id)$ 正则匹配参数中的路径参数
|
||||
method: 'post'
|
||||
|
@ -392,7 +404,6 @@ case_dir = /testcase
|
|||
cache_dir = /caches
|
||||
test_name = 测试项目名称: saasWeb
|
||||
[host]
|
||||
http_type = http
|
||||
host =
|
||||
[email]
|
||||
;服务器
|
||||
|
|
|
@ -19,7 +19,7 @@ Log()
|
|||
class apiSend(object):
|
||||
|
||||
def __init__(self):
|
||||
self.http_type = host_manage(hos="${http_type}$")
|
||||
# self.http_type = host_manage(hos="${http_type}$")
|
||||
self.rel = Cache()
|
||||
|
||||
@staticmethod
|
||||
|
@ -31,9 +31,10 @@ class apiSend(object):
|
|||
dataran = replace_random(data)
|
||||
return dataran
|
||||
|
||||
def post(self, address, header, caches, timeout=8, data=None, files=None, host="host"):
|
||||
def post(self, http, address, header, caches, timeout=8, data=None, files=None, host="host"):
|
||||
"""
|
||||
post请求
|
||||
:param http:
|
||||
:param host:
|
||||
:param caches: 关联情况
|
||||
- cachefrom: 'body' # response : 从结果中获取 body : 从参数中获取
|
||||
|
@ -53,7 +54,7 @@ class apiSend(object):
|
|||
"""
|
||||
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
url = http + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
data_random = self.iniDatas(data["param"])
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求方法:POST")
|
||||
|
@ -71,7 +72,7 @@ class apiSend(object):
|
|||
if isinstance(value, int):
|
||||
files[fileskey] = str(value)
|
||||
pass
|
||||
elif '/' in value or "\\" in value:
|
||||
elif "\\" in value:
|
||||
file_parm = fileskey
|
||||
files[file_parm] = (os.path.basename(value), open(value, 'rb'), 'application/octet-stream')
|
||||
else:
|
||||
|
@ -124,9 +125,10 @@ class apiSend(object):
|
|||
logging.error(response.text)
|
||||
raise
|
||||
|
||||
def get(self, address, caches, header, data, timeout=8, host="host"):
|
||||
def get(self, http, address, caches, header, data, timeout=8, host="host"):
|
||||
"""
|
||||
get请求
|
||||
:param http:
|
||||
:param host:
|
||||
:param caches: 关联情况
|
||||
- cachefrom: 'body' # response : 从结果中获取 body : 从参数中获取
|
||||
|
@ -143,7 +145,7 @@ class apiSend(object):
|
|||
# if "urlparam" in data.keys():
|
||||
# address = replace_random(address, param=data["urlparam"])
|
||||
data_random = self.iniDatas(data["param"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
url = http + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求方法:GET")
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
@ -169,9 +171,10 @@ class apiSend(object):
|
|||
logging.error(response.text)
|
||||
raise
|
||||
|
||||
def put(self, address, caches, header, timeout=8, data=None, files=None, host="host"):
|
||||
def put(self, http, address, caches, header, timeout=8, data=None, files=None, host="host"):
|
||||
"""
|
||||
put请求
|
||||
:param http:
|
||||
:param host:
|
||||
:param address:
|
||||
:param caches: 关联情况
|
||||
|
@ -186,7 +189,7 @@ class apiSend(object):
|
|||
:return:
|
||||
"""
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
url = http + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求方法:PUT")
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
@ -222,9 +225,10 @@ class apiSend(object):
|
|||
logging.error(response.text)
|
||||
raise
|
||||
|
||||
def delete(self, address, caches, header, data, timeout=8, host="host"):
|
||||
def delete(self, http, address, caches, header, data, timeout=8, host="host"):
|
||||
"""
|
||||
get请求
|
||||
:param http:
|
||||
:param host:
|
||||
:param caches: 关联情况
|
||||
- cachefrom: 'body' # response : 从结果中获取 body : 从参数中获取
|
||||
|
@ -238,7 +242,7 @@ class apiSend(object):
|
|||
"""
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
data_random = self.iniDatas(data["param"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
url = http + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求方法:DELETE")
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
@ -263,9 +267,21 @@ class apiSend(object):
|
|||
logging.error(response.text)
|
||||
raise
|
||||
|
||||
def patch(self, address, caches, header, timeout=8, data=None, files=None, host="host"):
|
||||
def patch(self, http, address, caches, header, timeout=8, data=None, files=None, host="host"):
|
||||
"""
|
||||
|
||||
:param http:
|
||||
:param address:
|
||||
:param caches:
|
||||
:param header:
|
||||
:param timeout:
|
||||
:param data:
|
||||
:param files:
|
||||
:param host:
|
||||
:return:
|
||||
"""
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
url = http + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求方法:PATHC")
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
@ -295,18 +311,18 @@ class apiSend(object):
|
|||
logging.error(response.text)
|
||||
raise
|
||||
|
||||
def __call__(self, address, method, headers, data, caches, **kwargs):
|
||||
def __call__(self, http, address, method, headers, data, caches, **kwargs):
|
||||
try:
|
||||
if method == "post" or method == 'POST':
|
||||
return self.post(address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
return self.post(http=http, address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
elif method == "get" or method == 'GET':
|
||||
return self.get(address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
return self.get(http=http, address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
elif method == "delete" or method == 'DELETE':
|
||||
return self.delete(address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
return self.delete(http=http, address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
elif method == "put" or method == 'PUT':
|
||||
return self.put(address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
return self.put(http=http, address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
elif method == "patch" or method == 'PATCH':
|
||||
return self.patch(address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
return self.patch(http=http, address=address, data=data, header=headers, caches=caches, **kwargs)
|
||||
else:
|
||||
raise TypeError(f"请求异常,检查yml文件method")
|
||||
except Exception:
|
||||
|
@ -314,23 +330,23 @@ class apiSend(object):
|
|||
|
||||
|
||||
apisend = apiSend()
|
||||
if __name__ == '__main__':
|
||||
# h = {
|
||||
# "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjE2OTRmYjlmLTUzNjYtNGZjZS1hODg4LTBlY2UxOThmZThhZSJ9.5_mD4abE-5iHsSr6RB9R8qaIRV7zidUFkpytyyd2cjSiQcrdJvAE_6GjU9Q_Xsr0JmTkSCTiefpFySguyk2E8Q",
|
||||
# "Content-Type": "multipart/form-data"
|
||||
#
|
||||
# }
|
||||
# d = {
|
||||
# "param": "updateSupport=0",
|
||||
# "urlparam": None
|
||||
# }
|
||||
# p = {'address': '/v1/enter/trade/', 'assert': {'jsonpath': None, 'sqlassert': None, 'time': 2, 'code': 201},
|
||||
# 'data': {'param': {'name': '行业名称$RandomString($RandomPosInt(2,6)$)$',
|
||||
# 'desc': '备注$RandomString($RandomPosInt(2,8)$)$'}, 'urlparam': None},
|
||||
# 'headers': {'Content-Type': 'application/json',
|
||||
# 'Authorization': 'GREEN eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMiwiZXhwIjoxNjUxODMzNjY4LCJ1c2VybmFtZSI6ImRsMDAxIn0.Dbk1ddEXdmW1tRzxZLvFgJwsh0hek6HJjzCabStdnz0'},
|
||||
# 'host': 'host_HB', 'info': '新建行业', 'method': 'POST', 'cache': None, 'relevance': None}
|
||||
# ress = apisend(address=p['address'], data=p['data'], method=p['method'], headers=p['headers'],
|
||||
# caches=p['cache'], host=p['host'], )
|
||||
# print(ress)
|
||||
d =pymysql
|
||||
# if __name__ == '__main__':
|
||||
# h = {
|
||||
# "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjE2OTRmYjlmLTUzNjYtNGZjZS1hODg4LTBlY2UxOThmZThhZSJ9.5_mD4abE-5iHsSr6RB9R8qaIRV7zidUFkpytyyd2cjSiQcrdJvAE_6GjU9Q_Xsr0JmTkSCTiefpFySguyk2E8Q",
|
||||
# "Content-Type": "multipart/form-data"
|
||||
#
|
||||
# }
|
||||
# d = {
|
||||
# "param": "updateSupport=0",
|
||||
# "urlparam": None
|
||||
# }
|
||||
# p = {'address': '/v1/enter/trade/', 'assert': {'jsonpath': None, 'sqlassert': None, 'time': 2, 'code': 201},
|
||||
# 'data': {'param': {'name': '行业名称$RandomString($RandomPosInt(2,6)$)$',
|
||||
# 'desc': '备注$RandomString($RandomPosInt(2,8)$)$'}, 'urlparam': None},
|
||||
# 'headers': {'Content-Type': 'application/json',
|
||||
# 'Authorization': 'GREEN eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMiwiZXhwIjoxNjUxODMzNjY4LCJ1c2VybmFtZSI6ImRsMDAxIn0.Dbk1ddEXdmW1tRzxZLvFgJwsh0hek6HJjzCabStdnz0'},
|
||||
# 'host': 'host_HB', 'info': '新建行业', 'method': 'POST', 'cache': None, 'relevance': None}
|
||||
# ress = apisend(address=p['address'], data=p['data'], method=p['method'], headers=p['headers'],
|
||||
# caches=p['cache'], host=p['host'], )
|
||||
# print(ress)
|
||||
# d =pymysql
|
||||
|
|
|
@ -12,8 +12,6 @@ file_dir = /file
|
|||
|
||||
test_name = demo
|
||||
[host]
|
||||
http_type = https
|
||||
|
||||
demo = wanandroid.com
|
||||
[email]
|
||||
;服务器
|
||||
|
|
|
@ -3,8 +3,10 @@ shoucang:
|
|||
order: 1
|
||||
token: Cookies
|
||||
file: false
|
||||
encryption: false
|
||||
case:
|
||||
- address: /lg/collect/add/json
|
||||
http: https
|
||||
assert:
|
||||
jsonpath:
|
||||
sqlassert: null
|
||||
|
@ -12,7 +14,7 @@ shoucang:
|
|||
code: 400
|
||||
data:
|
||||
file:
|
||||
param: 'title=2&author=2&link=2'
|
||||
param: 2022-01-01
|
||||
urlparam: null
|
||||
headers:
|
||||
Content-Type: multipart/form-data
|
||||
|
|
|
@ -3,8 +3,10 @@ login:
|
|||
order: 1
|
||||
token: false
|
||||
file: false
|
||||
encryption: false
|
||||
case:
|
||||
- address: /user/login
|
||||
http: https
|
||||
assert:
|
||||
jsonpath:
|
||||
sqlassert: null
|
||||
|
|
|
@ -17,7 +17,7 @@ class Test_biaodan(object):
|
|||
casedata["headers"] = iniheaders(casedata["headers"])
|
||||
casedata["headers"]["Cookies"] = "$caches(cookie)$"
|
||||
casedata = relevance(casedata, setup_Login)
|
||||
res, restime, code = apisend(host=casedata["host"], address=casedata["address"], method=casedata["method"],
|
||||
res, restime, code = apisend(http=casedata["http"],host=casedata["host"], address=casedata["address"], method=casedata["method"],
|
||||
headers=casedata["headers"],
|
||||
data=casedata["data"], caches=casedata["cache"])
|
||||
caseTearDown(casedata, res, setup_Login)
|
||||
|
|
|
@ -14,8 +14,10 @@ class Test_login(object):
|
|||
ids=[i["info"] for i in readRedisData("login")["case"]])
|
||||
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||
def test_login(self, casedata):
|
||||
res, restime, code = apisend(host=casedata["host"], address=casedata["address"], method=casedata["method"],
|
||||
res, restime, code = apisend(http=casedata["http"], host=casedata["host"], address=casedata["address"],
|
||||
method=casedata["method"],
|
||||
headers=casedata["headers"],
|
||||
data=casedata["data"], caches=casedata["cache"])
|
||||
|
||||
caseTearDown(casedata, res)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime, re_code=code)
|
||||
|
|
|
@ -63,11 +63,14 @@ class Test_{filename}(object):""")
|
|||
casedata = relevance(casedata, setup_Login)""")
|
||||
else:
|
||||
f.write(f"""
|
||||
def test_{item}(self, casedata):""")
|
||||
def test_{item}(self, casedata):
|
||||
casedata = relevance(casedata)""")
|
||||
if not filedata[item]["file"]:
|
||||
# 判断是否存上传文件
|
||||
f.write("""
|
||||
res, restime, code = apisend(host=casedata["host"], address=casedata["address"], method=casedata["method"],
|
||||
|
||||
res, restime, code = apisend(http=casedata["http"], host=casedata["host"], address=casedata["address"],
|
||||
method=casedata["method"],
|
||||
headers=casedata["headers"],
|
||||
data=casedata["data"], caches=casedata["cache"])""")
|
||||
if not filedata[item]["token"]:
|
||||
|
@ -80,18 +83,19 @@ class Test_{filename}(object):""")
|
|||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime, re_code=code)\n""")
|
||||
else:
|
||||
f.write(f"""
|
||||
res, restime, code = apisend(host=casedata["host"], address=casedata["address"], method=casedata["method"],
|
||||
res, restime, code = apisend(http=casedata["http"], host=casedata["host"], address=casedata["address"],
|
||||
method=casedata["method"],
|
||||
headers=casedata["headers"],
|
||||
data=casedata["data"], caches=casedata["cache"],
|
||||
files=casedata["data"]["file"])""")
|
||||
if not filedata[item]["token"]:
|
||||
f.write(f"""
|
||||
caseTearDown(casedata, res)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime, re_code=code)\n""")
|
||||
caseTearDown(casedata, res)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime, re_code=code)\n""")
|
||||
else:
|
||||
f.write(f"""
|
||||
caseTearDown(casedata, res, setup_Login)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime, re_code=code)\n""")
|
||||
caseTearDown(casedata, res, setup_Login)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime, re_code=code)\n""")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -47,7 +47,7 @@ def relevance (relevancedata, headerdata=None):
|
|||
relcase["headers"] = iniheaders(relcase["headers"])
|
||||
relcase["headers"][case["token"]] = headerdata
|
||||
# 进行关联接口请求
|
||||
res, time, code = apisend(address=relcase["address"],
|
||||
res, time, code = apisend(http=relcase["http"],address=relcase["address"],
|
||||
method=relcase["method"], headers=relcase["headers"],
|
||||
data=relcase["data"],
|
||||
caches=relcase["cache"], host=relcase["host"])
|
||||
|
|
|
@ -234,8 +234,7 @@ def replace_random(value, res=None, param=None):
|
|||
int_list_json = re.findall(r'\"\$RandomInt\(([0-9]*,[0-9]*?)\)\$\"', value)
|
||||
int_list_dict = re.findall(r'\'\$RandomInt\(([0-9]*,[0-9]*?)\)\$\'', value)
|
||||
string_list = re.findall(r'\$RandomString\(([0-9]*?)\)\$', value)
|
||||
float_list_json = re.findall(r'\"\$RandomFloat\(([0-9]*,[0-9]*,[0-9]*)\)\$\"', value)
|
||||
float_list_dict = re.findall(r'\'\$RandomFloat\(([0-9]*,[0-9]*,[0-9]*)\)\$\'', value)
|
||||
float_list = re.findall(r'\"\$RandomFloat\(([0-9]*,[0-9]*,[0-9]*)\)\$\"', value)
|
||||
posfloat_list = re.findall(r'\$RandomPosFloat\(([0-9]*,[0-9]*,[0-9]*)\)\$', value)
|
||||
time_list = re.findall(r"\$GetTime\(time_type=(.*?),layout=(.*?),unit=([0-9],[0-9],[0-9],[0-9],[0-9])\)\$", value)
|
||||
choice_list = re.findall(r"\$Choice\((.*?)\)\$", value)
|
||||
|
@ -247,20 +246,20 @@ def replace_random(value, res=None, param=None):
|
|||
|
||||
if len(int_list_json):
|
||||
# 获取整型数据替换 结果是int
|
||||
# int类型必须格式定死为双引号覆盖 ' "$RandomInt(1,333)$" '
|
||||
for i in int_list_json:
|
||||
pattern = re.compile(r'\"\$RandomInt\(' + i + r'\)\$\"')
|
||||
key = str(random_int(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(int_list_dict):
|
||||
# 获取整型数据替换 结果是int
|
||||
# int类型必须格式定死为双引号覆盖 ' "$RandomInt(1,333)$" '
|
||||
for i in int_list_dict:
|
||||
pattern = re.compile(r'\'\$RandomInt\(' + i + r'\)\$\'')
|
||||
key = str(random_int(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(posint_list):
|
||||
# 获取整型数据替换 结果是字符串
|
||||
for i in posint_list:
|
||||
|
@ -268,7 +267,6 @@ def replace_random(value, res=None, param=None):
|
|||
key = str(random_int(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(string_list):
|
||||
# 获取字符串数据替换
|
||||
for i in string_list:
|
||||
|
@ -277,30 +275,14 @@ def replace_random(value, res=None, param=None):
|
|||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(float_list_json):
|
||||
elif len(float_list):
|
||||
# 获取浮点数数据替换 返回浮点
|
||||
for i in float_list_json:
|
||||
for i in float_list:
|
||||
pattern = re.compile(r'\"\$RandomFloat\(' + i + r'\)\$\"')
|
||||
key = str(random_float(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(float_list_json):
|
||||
# 获取浮点数数据替换 返回浮点
|
||||
for i in float_list_json:
|
||||
pattern = re.compile(r'\"\$RandomFloat\(' + i + r'\)\$\"')
|
||||
key = str(random_float(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(float_list_dict):
|
||||
# 获取浮点数数据替换 返回浮点
|
||||
for i in float_list_dict:
|
||||
pattern = re.compile(r'\'\$RandomFloat\(' + i + r'\)\$\'')
|
||||
key = str(random_float(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(posfloat_list):
|
||||
# 获取浮点数数据替换 返回str
|
||||
for i in posfloat_list:
|
||||
|
@ -308,7 +290,6 @@ def replace_random(value, res=None, param=None):
|
|||
key = str(random_float(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(time_list):
|
||||
# 获取时间替换
|
||||
for i in time_list:
|
||||
|
@ -336,6 +317,7 @@ def replace_random(value, res=None, param=None):
|
|||
value = replace_random(value, res, param)
|
||||
|
||||
elif len(urlparam_list):
|
||||
|
||||
# urls = "$url(home_id)$"
|
||||
# replace_random(urls,param={"home_id":"$caches(haha)$"})
|
||||
for i in urlparam_list:
|
||||
|
@ -345,6 +327,7 @@ def replace_random(value, res=None, param=None):
|
|||
value = replace_random(value, res, param=param)
|
||||
|
||||
elif len(relevance_list):
|
||||
|
||||
# urls = "$url(home_id)$"
|
||||
# replace_random(urls,param={"home_id":"$caches(haha)$"})
|
||||
for i in relevance_list:
|
||||
|
@ -461,11 +444,7 @@ from alarm
|
|||
# a = replace_random(str(d),param=p)
|
||||
# print(a)
|
||||
time_num2 = '$GetTime(time_type=past,layout=%Y-%m-%d %H:%M:%S,unit=0,0,0,3,0)$' # 当前时间 2022-04-14 13:27:01
|
||||
da = {"data": {
|
||||
"param": {'mch_id': "$RandomFloat(1,333,2)$", 'nonce_str': 'eh0k52jvvvs51dbxr2pd', 'out_trade_no': 10002112123231,
|
||||
'sign': '{{sign}}'}}}
|
||||
da = {"data": {"param":{'mch_id': "$RandomInt(1,333)$", 'nonce_str': 'eh0k52jvvvs51dbxr2pd', 'out_trade_no': 10002112123231,
|
||||
'sign': '{{sign}}'}}}
|
||||
da2 = '"$RandomInt(1,333)$"'
|
||||
r = eval(replace_random(da))
|
||||
print(r)
|
||||
print(type(r["data"]["param"]["mch_id"]))
|
||||
|
||||
print(eval(replace_random(da)))
|
||||
|
|
|
@ -64,7 +64,7 @@ def caseTearDown(casedata, caseres, headerdata=None):
|
|||
tddata['dataname']: value
|
||||
}
|
||||
# 执行后置请求
|
||||
res,code,restime = apisend(address=tdcase["address"],
|
||||
res,code,restime = apisend(http=tdcase["http"],address=tdcase["address"],
|
||||
method=tdcase["method"], headers=tdcase["headers"],
|
||||
data=tdcase["data"],
|
||||
caches=tdcase["cache"], host=tdcase["host"])
|
||||
|
|
Loading…
Reference in New Issue