| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- from fastapi.testclient import TestClient
- import app.main as main
- class FakeHost:
- async def list_runs(self, _headers):
- return {
- "items": [
- {
- "id": 42,
- "status": "running",
- "summary": "正在生成脚本",
- "start_time": "2026-07-21T01:00:00Z",
- "end_time": None,
- }
- ]
- }
- def test_runs_are_normalized_from_host(monkeypatch) -> None:
- monkeypatch.setattr(main, "host", FakeHost())
- response = TestClient(main.app).get("/api/runs")
- assert response.status_code == 200
- assert response.json()[0] == {
- "script_build_id": 42,
- "status": "running",
- "summary": "正在生成脚本",
- "started_at": "2026-07-21T01:00:00Z",
- "completed_at": None,
- }
- def test_browser_auth_credentials_are_allowed_for_the_frontend() -> None:
- response = TestClient(main.app).options(
- "/api/runs",
- headers={
- "Origin": "http://127.0.0.1:3008",
- "Access-Control-Request-Method": "GET",
- },
- )
- assert response.headers["access-control-allow-origin"] == "http://127.0.0.1:3008"
- assert response.headers["access-control-allow-credentials"] == "true"
|