style: apply black formatting to pass CI validation (#126)
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
This commit was merged in pull request #126.
This commit is contained in:
+49
-36
@@ -4,6 +4,7 @@
|
||||
用法: python3 smoke_test.py <API_BASE_URL> [--email EMAIL] [--password PASSWORD] [--json]
|
||||
示例: python3 smoke_test.py https://saas-api.xiaoxiajianji.com --email test@example.com --password test123 --json
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
@@ -13,19 +14,29 @@ import urllib.error
|
||||
import ssl
|
||||
|
||||
CORE_ENDPOINTS = [
|
||||
{"name": "upload/direct/prepare", "method": "POST", "path": "/api/v1/upload/direct/prepare",
|
||||
"body": {"project_id": "smoke-test", "file_name": "test.mp4", "file_size": 1024, "content_type": "video/mp4"},
|
||||
"expect": [200, 401, 422]},
|
||||
{"name": "upload/chunk/init", "method": "POST", "path": "/api/v1/upload/chunk/init",
|
||||
"body": {"project_id": "smoke-test", "file_name": "test.mp4", "file_size": 1024000, "total_chunks": 2},
|
||||
"expect": [200, 401, 422]},
|
||||
{"name": "dashboard/overview", "method": "GET", "path": "/api/v1/dashboard/overview",
|
||||
"expect": [200, 401]},
|
||||
{"name": "assets", "method": "GET", "path": "/api/v1/assets?library_id=smoke-test",
|
||||
"expect": [200, 401]},
|
||||
{"name": "generation/tasks", "method": "POST", "path": "/api/v1/generation/tasks",
|
||||
"body": {},
|
||||
"expect": [200, 401, 422]},
|
||||
{
|
||||
"name": "upload/direct/prepare",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/upload/direct/prepare",
|
||||
"body": {"project_id": "smoke-test", "file_name": "test.mp4", "file_size": 1024, "content_type": "video/mp4"},
|
||||
"expect": [200, 401, 422],
|
||||
},
|
||||
{
|
||||
"name": "upload/chunk/init",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/upload/chunk/init",
|
||||
"body": {"project_id": "smoke-test", "file_name": "test.mp4", "file_size": 1024000, "total_chunks": 2},
|
||||
"expect": [200, 401, 422],
|
||||
},
|
||||
{"name": "dashboard/overview", "method": "GET", "path": "/api/v1/dashboard/overview", "expect": [200, 401]},
|
||||
{"name": "assets", "method": "GET", "path": "/api/v1/assets?library_id=smoke-test", "expect": [200, 401]},
|
||||
{
|
||||
"name": "generation/tasks",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/generation/tasks",
|
||||
"body": {},
|
||||
"expect": [200, 401, 422],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -34,14 +45,14 @@ def make_request(base_url, endpoint, token=None):
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
|
||||
|
||||
data = json.dumps(endpoint.get("body", {})).encode() if endpoint.get("body") is not None else None
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=endpoint["method"])
|
||||
|
||||
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
|
||||
|
||||
try:
|
||||
start = time.time()
|
||||
resp = urllib.request.urlopen(req, timeout=15, context=ctx)
|
||||
@@ -78,15 +89,15 @@ def login(base_url, email, password):
|
||||
def run_smoke_test(base_url, email=None, password=None, output_json=False):
|
||||
base_url = base_url.rstrip("/")
|
||||
token = None
|
||||
|
||||
|
||||
if email and password:
|
||||
token = login(base_url, email, password)
|
||||
if not output_json:
|
||||
print(f"{'✅ 登录成功' if token else '⚠️ 登录失败,将以未认证模式测试'}")
|
||||
|
||||
|
||||
results = []
|
||||
all_passed = True
|
||||
|
||||
|
||||
for ep in CORE_ENDPOINTS:
|
||||
result = make_request(base_url, ep, token)
|
||||
passed = result["status"] in ep["expect"] and result["error"] is None
|
||||
@@ -94,24 +105,26 @@ def run_smoke_test(base_url, email=None, password=None, output_json=False):
|
||||
if is_5xx:
|
||||
passed = False
|
||||
all_passed = False
|
||||
|
||||
results.append({
|
||||
"name": ep["name"],
|
||||
"path": ep["path"],
|
||||
"status": result["status"],
|
||||
"elapsed_ms": result["elapsed_ms"],
|
||||
"passed": passed,
|
||||
"error": result["error"],
|
||||
"is_5xx": is_5xx
|
||||
})
|
||||
|
||||
|
||||
results.append(
|
||||
{
|
||||
"name": ep["name"],
|
||||
"path": ep["path"],
|
||||
"status": result["status"],
|
||||
"elapsed_ms": result["elapsed_ms"],
|
||||
"passed": passed,
|
||||
"error": result["error"],
|
||||
"is_5xx": is_5xx,
|
||||
}
|
||||
)
|
||||
|
||||
if not output_json:
|
||||
icon = "✅" if passed else "❌"
|
||||
print(f" {icon} {ep['name']}: {result['status']} ({result['elapsed_ms']}ms)")
|
||||
|
||||
|
||||
if output_json:
|
||||
print(json.dumps({"success": all_passed, "results": results, "base_url": base_url}, indent=2))
|
||||
|
||||
|
||||
return 0 if all_passed else 1
|
||||
|
||||
|
||||
@@ -122,17 +135,17 @@ def main():
|
||||
parser.add_argument("--password", help="登录密码")
|
||||
parser.add_argument("--json", action="store_true", help="JSON 格式输出")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if not args.json:
|
||||
print(f"\n🔍 冒烟测试: {args.base_url}")
|
||||
print("-" * 50)
|
||||
|
||||
|
||||
exit_code = run_smoke_test(args.base_url, args.email, args.password, args.json)
|
||||
|
||||
|
||||
if not args.json:
|
||||
print("-" * 50)
|
||||
print(f"{'✅ 全部通过' if exit_code == 0 else '❌ 存在失败端点'}\n")
|
||||
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user