From 9c7ff9c48910e5dc83f8f8d177d6420bf2880e7b Mon Sep 17 00:00:00 2001 From: Mplan Date: Sun, 26 Jul 2026 01:24:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99=E7=9A=84?= =?UTF-8?q?=20test=5Fapi.py=EF=BC=8C=E5=85=B6=E6=89=80=E6=9C=89=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E7=82=B9=E5=B7=B2=E8=A2=AB=E6=A8=A1=E5=9D=97=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9B=BF=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_api.py | 127 ---------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 tests/test_api.py diff --git a/tests/test_api.py b/tests/test_api.py deleted file mode 100644 index f662cd4..0000000 --- a/tests/test_api.py +++ /dev/null @@ -1,127 +0,0 @@ -from fastapi.testclient import TestClient - -from tests.conftest import bearer, capture_email, confirm_email, png_bytes - - -def test_openapi_contains_all_feature_groups(client: TestClient) -> None: - response = client.get("/openapi.json") - assert response.status_code == 200 - paths = response.json()["paths"] - expected = { - "/api/v1/auth/register", - "/api/v1/auth/login", - "/api/v1/cloud-types", - "/api/v1/clouds", - "/api/v1/clouds/map", - "/api/v1/collections/me", - "/api/v1/profiles/{user_id}/clouds", - "/api/v1/admin/stats", - } - assert expected <= set(paths) - - -def test_complete_user_cloud_and_admin_flow(client: TestClient, monkeypatch) -> None: - captured_tokens = capture_email(monkeypatch) - - health = client.get("/api/v1/health") - assert health.status_code == 200 - - registered = client.post( - "/api/v1/auth/register", - json={ - "email": "observer@example.com", - "password": "observer-password-123", - "username": "观云者", - }, - ) - assert registered.status_code == 201 - assert "token" in captured_tokens - - confirmed = confirm_email(client, captured_tokens["token"]) - assert confirmed.status_code == 200 - - login = client.post( - "/api/v1/auth/login", - json={"email": "observer@example.com", "password": "observer-password-123"}, - ) - assert login.status_code == 200 - user_token = login.json()["access_token"] - user_id = login.json()["user"]["id"] - - me = client.get("/api/v1/auth/me", headers=bearer(user_token)) - assert me.status_code == 200 - assert me.json()["profile"]["username"] == "观云者" - - renamed = client.patch( - "/api/v1/profiles/me", - headers=bearer(user_token), - json={"username": "天空观察员"}, - ) - assert renamed.status_code == 200 - - upload = client.post( - "/api/v1/clouds", - headers=bearer(user_token), - files={"image": ("cloud.png", png_bytes(), "image/png")}, - data={ - "cloud_type_id": "1", - "latitude": "31.2345", - "longitude": "121.4737", - "location_name": "上海", - "description": "测试云图", - "captured_at": "2026-07-18T10:00:00+08:00", - "is_hidden": "false", - }, - ) - assert upload.status_code == 201, upload.text - cloud = upload.json()["cloud"] - cloud_id = cloud["id"] - assert cloud["status"] == "pending" - assert cloud["latitude"] == 31.23 - assert upload.json()["unlocked_badge"]["cloud_type_id"] == 1 - - collection = client.get("/api/v1/collections/me", headers=bearer(user_token)) - assert collection.status_code == 200 - assert len(collection.json()) == 1 - - hidden_from_gallery = client.get("/api/v1/clouds") - assert hidden_from_gallery.json()["total"] == 0 - - admin_login = client.post( - "/api/v1/auth/login", - json={"email": "admin@example.com", "password": "admin-password-123"}, - ) - assert admin_login.status_code == 200 - admin_token = admin_login.json()["access_token"] - approved = client.patch( - "/api/v1/admin/clouds/status", - headers=bearer(admin_token), - json={"ids": [cloud_id], "status": "approved"}, - ) - assert approved.status_code == 200 - assert approved.json()["updated"] == 1 - - gallery = client.get("/api/v1/clouds", params={"search": "积云"}) - assert gallery.status_code == 200 - assert gallery.json()["total"] == 1 - - map_clouds = client.get( - "/api/v1/clouds/map", - params={ - "start": "2026-07-18T00:00:00+08:00", - "end": "2026-07-19T00:00:00+08:00", - }, - ) - assert map_clouds.status_code == 200 - assert len(map_clouds.json()) == 1 - - public_profile_clouds = client.get(f"/api/v1/profiles/{user_id}/clouds") - assert public_profile_clouds.status_code == 200 - assert public_profile_clouds.json()["total"] == 1 - - deleted = client.delete(f"/api/v1/clouds/{cloud_id}", headers=bearer(user_token)) - assert deleted.status_code == 200 - assert deleted.json()["deleted"] == 1 - - logout = client.post("/api/v1/auth/logout") - assert logout.status_code == 200