Compare commits

..

2 Commits

Author SHA1 Message Date
long2ice
818bb523dd
Update command.py 2025-03-21 15:05:34 +08:00
bobo.yang
078c0d52c5 update apiauth_id 2025-03-21 15:03:44 +08:00

View File

@ -30,7 +30,8 @@ def get_apidocs():
return res.json()["docs"]
def delete_old_apidocs(apidocs):
def delete_old_apidocs():
apidocs = get_apidocs()
for apidoc in apidocs:
session.delete(f"{SERVER_URL}/autotest/projects/{PROJECT_ID}/apidocs/{apidoc['id']}")
@ -48,13 +49,13 @@ def check_api_version():
return
local_version = get_local_version()
print("检查被测服务器文档是否已经更新到最新版本...", flush=True)
print("检查被测服务器文档是否已经更新到最新版本...")
while True:
try:
res = session.get(VERSION_URL)
version = res.json()["version"]
if version == local_version:
print(f"API 文档已更新,当前版本为 {version},开始上传 OpenAPI 文档...", flush=True)
print(f"API 文档已更新,当前版本为 {version},开始上传 OpenAPI 文档...")
break
else:
print(
@ -126,11 +127,7 @@ def wait_for_task_done(task_id):
res = session.get(f"{SERVER_URL}/tasks/{task_id}")
data = res.json()
status = data["status"]
CREATED = "created"
RUNNING = "running"
WAITING = "waiting"
if status not in [CREATED, RUNNING, WAITING]:
if status == "succeeded":
print("自动测试脚本执行完成!", flush=True)
break
else:
@ -165,10 +162,10 @@ def main():
api_path = args[0]
method = args[1]
test_target = " ".join(args[2:])
docs = get_apidocs()
with Step("检查 API 版本是否更新..."):
check_api_version()
delete_old_apidocs(docs)
delete_old_apidocs()
with Step(f"上传 OpenAPI 文档,并且触发 API {api_path} 的测试用例和自动测试脚本生成任务..."):
# 使用配置的OPENAPI_URL
@ -182,7 +179,7 @@ def main():
res = session.post(
f"{SERVER_URL}/autotest/projects/{PROJECT_ID}/apidocs",
files={"file": ("openapi.json", res.content, "application/json")},
data={"apiauth_id": docs[0]["apiauth_id"]},
data={"apiauth_id": 1},
)
if res.status_code == 200:
print("上传 OpenAPI 文档成功!\n")
@ -230,6 +227,14 @@ def main():
api_path_id = get_path_op_id(api_path, method)
with Step("开始查询测试脚本执行结果..."):
while True:
res = session.get(
f"{SERVER_URL}/autotest/projects/{PROJECT_ID}/tasks",
params={"page": 1, "size": 1},
)
ret = res.json()
task = ret["tasks"][0]
task_id = task["id"]
wait_for_task_done(task_id)
testcase = get_testcase(api_path_id)
last_testcode_passed = testcase["last_testcode_passed"]
if last_testcode_passed: