Compare commits

...

6 Commits

Author SHA1 Message Date
boob.yang
c3de57a2b3
Merge pull request #145 from devchat-ai/update_test_api3
refactor: Remove redundant task query in test API upload command
2025-03-21 13:29:19 +00:00
bobo.yang
f2f0a10a9e refactor: Remove redundant task query in test API upload command
- Remove unnecessary API call to fetch tasks
- Simplify test execution flow by eliminating wait_for_task_done call
- Improve code efficiency in the test API upload command
2025-03-21 21:24:46 +08:00
long2ice
607ce67792
Merge pull request #144 from devchat-ai/update_test_api2
fix: Add flush=True to print statements and improve task status check
2025-03-21 11:35:34 +00:00
bobo.yang
42c4386562 fix: Add flush=True to print statements and improve task status check
- Added flush=True to print statements for better real-time logging
- Replaced single status check with a list of statuses to continue waiting
- Defined constants for task status values for better code readability
2025-03-21 19:28:49 +08:00
boob.yang
0be6ca7e33
Merge pull request #143 from devchat-ai/api-auth
refactor: get api auth id from docs
2025-03-21 10:11:57 +00:00
long2ice
21fe8dd34f refactor: Update delete_old_apidocs function to accept apidocs as a parameter
This commit modifies the delete_old_apidocs function to take a list of apidocs as an argument, ensuring it operates on the current set of API documentation. Additionally, it updates the main function to pass the retrieved apidocs when calling delete_old_apidocs.
2025-03-21 18:10:21 +08:00

View File

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