627bd5b6a2
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m10s
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 55s
CI/CD Pipeline / Frontend Lint (push) Successful in 27s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 1m48s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 4m44s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 4m46s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 41s
CI/CD Pipeline / Integration Tests (push) Successful in 2m17s
CI/CD Pipeline / Unit Tests (push) Successful in 5m4s
CI/CD Pipeline / Build Staging API Image (push) Successful in 14m18s
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m16s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 14s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 14s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 41s
修复scripts目录下ruff检测到的18个问题:F841未使用变量6处、F401未使用import 10处、B007未使用循环变量1处、F541 f-string缺少占位符1处。
109 lines
2.9 KiB
Python
109 lines
2.9 KiB
Python
"""Public upload smoke for the SaaS Web-domain API path.
|
|
|
|
This intentionally uses https://saas.xiaoxiajianji.com/api/v1 so the Web nginx
|
|
proxy is tested together with the API upload path.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import os
|
|
import time
|
|
import uuid
|
|
|
|
import requests
|
|
|
|
BASE_URL = "https://saas.xiaoxiajianji.com/api/v1"
|
|
PASSWORD = os.environ.get("SMOKE_TEST_PASSWORD", "changeme")
|
|
|
|
|
|
def _json_or_raise(name: str, response: requests.Response) -> dict:
|
|
print(f"{name}={response.status_code}")
|
|
if response.status_code >= 400:
|
|
print(response.text[:1000])
|
|
response.raise_for_status()
|
|
if not response.content:
|
|
return {}
|
|
return response.json()
|
|
|
|
|
|
def main() -> None:
|
|
session = requests.Session()
|
|
suffix = uuid.uuid4().hex[:10]
|
|
email = f"smoke-upload-{suffix}@example.com"
|
|
username = f"smoke_upload_{suffix}"
|
|
|
|
_json_or_raise(
|
|
"register",
|
|
session.post(
|
|
f"{BASE_URL}/auth/register",
|
|
json={"email": email, "username": username, "password": PASSWORD, "full_name": "Upload Smoke"},
|
|
timeout=30,
|
|
),
|
|
)
|
|
login = _json_or_raise(
|
|
"login",
|
|
session.post(f"{BASE_URL}/auth/login", json={"email": email, "password": PASSWORD}, timeout=30),
|
|
)
|
|
headers = {"Authorization": f"Bearer {login['access_token']}"}
|
|
|
|
_json_or_raise(
|
|
"workspace",
|
|
session.post(f"{BASE_URL}/workspaces", json={"name": "Upload Smoke Workspace"}, headers=headers, timeout=30),
|
|
)
|
|
|
|
project = _json_or_raise(
|
|
"project",
|
|
session.post(
|
|
f"{BASE_URL}/projects",
|
|
headers=headers,
|
|
timeout=30,
|
|
),
|
|
)
|
|
project_id = project["id"]
|
|
|
|
library = _json_or_raise(
|
|
"library",
|
|
session.post(
|
|
f"{BASE_URL}/asset-libraries",
|
|
json={
|
|
"project_id": project_id,
|
|
"name": "Smoke Video Library",
|
|
"kind": "video",
|
|
},
|
|
headers=headers,
|
|
timeout=30,
|
|
),
|
|
)
|
|
library["id"]
|
|
|
|
upload = _json_or_raise(
|
|
"upload",
|
|
session.post(
|
|
f"{BASE_URL}/upload",
|
|
files={"file": ("smoke.txt", io.BytesIO(b"xiaoxia upload smoke"), "text/plain")},
|
|
headers=headers,
|
|
timeout=60,
|
|
),
|
|
)
|
|
|
|
job_id = upload["ingest_job_id"]
|
|
latest_job = {}
|
|
for attempt in range(10):
|
|
latest_job = _json_or_raise(
|
|
f"ingest_{attempt}",
|
|
session.get(f"{BASE_URL}/ingest-jobs/{job_id}", headers=headers, timeout=30),
|
|
)
|
|
if latest_job.get("status") in {"completed", "failed"}:
|
|
break
|
|
time.sleep(1)
|
|
|
|
if latest_job.get("status") == "failed":
|
|
raise RuntimeError(f"ingest job failed: {latest_job.get('error_message')}")
|
|
|
|
print("public_upload_flow=ok")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|