1 Star 0 Fork 11

supassxu/python 接口自动化

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
locust_attestation1.py 3.48 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
# @Author : supassxu
# @time : 2021/4/29 10:26
# @File : locust_attestation1.py
# @Software : interface_test_dataqin
import time
from locust import TaskSet, task, HttpUser
class MyTasks(TaskSet):
"""
创建测试任务类,需要继承TaskSet
可以添加多个测试任务
"""
@task(1)
def attestation_attestations(self):
# 生成存证数据(表格)接口
requestId = str(int(time.time()*1000))
try:
url = "http://192.168.253.185:8081/preposition/attestation/attestations"
payload = {
"requestId": requestId,
"tonce": 15451,
"parameterLoad": "{\"attachments\":{\"back\":{\"fileUrl\":\"202103/1617171644091478_原告授权委托书.pdf\"}},\"business\":{\"businessSerialNumber\":\"" + requestId + "\",\"certificateName\":\"" + "auto" + requestId + "\",\"certificateNumber\":\"913306216725921760\",\"certificateType\":\"1\",\"contractNo\":\"" + requestId + "\",\"organizationName\":\"渣打银行\",\"productNumber\":\"test_temple\",\"organizationNumber\":\"913306216725921760\"},\"factoid\":{\"data\":{\"name\":\"" + "auto" + requestId + "\",\"type\":\"身份证\",\"number\":\"230111197104266110\",\"phone\":\"18658176223\",\"back\":\"21212121\"},\"type\":\"11\"},\"templateId\":\"CZ-00032\"}",
"signature": "11"
}
header = {"Content-Type": "application/json"}
res = self.client.post(url, headers=header, json=payload).json()
# print(res)
if res['flag'] is True:
print("success")
else:
print("fails")
# return res
except Exception as e:
print(e)
# @task(11)
# def attestation_info(self):
# # 存证结果校验接口
# try:
# url = "http://192.168.253.185:8081/preposition/attestation/info"
# payload = {
# "uscId": "913306216725921760",
# "id": requestId,
# "flag": 0
# }
# header = {"Content-Type": "application/json"}
# res = self.client.post(url, headers=header, json=payload).json()
# # print(res)
# if res['flag'] is True:
# print("success")
# else:
# print("fails")
# # return res
# except Exception as e:
# print(e)
#
# @task(21)
# def attestation_test(self):
# # 快速生成存证数据的区块链文件及hash接口
# try:
# url = "http://192.168.253.185:8081/preposition/attestation/test"
# res = self.client.get(url).json()
# # print(res)
# if res['flag'] is True:
# print("success")
# else:
# print("fails")
# except Exception as e:
# print(e)
# 每个测试任务,往往会以实例方法的形式来呈现
# 同时需要使用task装饰器来装饰测试任务
class websitUser(HttpUser):
"""
创建运行测试类,需要继承Locust父类
"""
tasks = [MyTasks] # 指定测试任务类,使用task_set覆盖父类的类属性
min_wait = 2000 # 指定启动任务间隔的时间范围(单位毫秒):2~5秒之间
max_wait = 5000 # 使用min_wait、max_wait覆盖父类的类属性
if __name__ == "__main__":
import os
os.system("locust -f locust_attestation1.py --host=http://192.168.253.185:8081")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/supassxu/interface_test_framework.git
git@gitee.com:supassxu/interface_test_framework.git
supassxu
interface_test_framework
python 接口自动化
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385