删除云图时自动同步图鉴:移除无云图的类型、替换首个云图引用,补充测试覆盖
This commit is contained in:
@@ -2,7 +2,7 @@ import uuid
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from tests.conftest import bearer, png_bytes, register_and_confirm
|
||||
from tests.conftest import bearer, png_bytes, register_and_confirm, upload_cloud
|
||||
|
||||
|
||||
def test_my_collections_after_upload(client: TestClient, monkeypatch) -> None:
|
||||
@@ -30,3 +30,64 @@ def test_my_collections_after_upload(client: TestClient, monkeypatch) -> None:
|
||||
def test_my_collections_unauthenticated(client: TestClient) -> None:
|
||||
r = client.get("/api/v1/collections/me")
|
||||
assert r.status_code == 401
|
||||
|
||||
|
||||
def test_collection_removed_after_deleting_last_cloud(client: TestClient, monkeypatch) -> None:
|
||||
info = register_and_confirm(
|
||||
client, monkeypatch,
|
||||
f"coll-delete-{uuid.uuid4().hex[:8]}@example.com",
|
||||
"collpass1", "图鉴删除用户",
|
||||
)
|
||||
upload = upload_cloud(client, info["token"], cloud_type_id="1")
|
||||
cloud_id = upload.json()["cloud"]["id"]
|
||||
|
||||
r = client.delete(f"/api/v1/clouds/{cloud_id}", headers=bearer(info["token"]))
|
||||
assert r.status_code == 200
|
||||
|
||||
r = client.get("/api/v1/collections/me", headers=bearer(info["token"]))
|
||||
assert r.status_code == 200
|
||||
assert r.json() == []
|
||||
|
||||
r = client.get("/api/v1/profiles/me", headers=bearer(info["token"]))
|
||||
assert r.status_code == 200
|
||||
assert r.json()["collection_count"] == 0
|
||||
|
||||
|
||||
def test_collection_uses_next_cloud_after_deleting_first(client: TestClient, monkeypatch) -> None:
|
||||
info = register_and_confirm(
|
||||
client, monkeypatch,
|
||||
f"coll-replace-{uuid.uuid4().hex[:8]}@example.com",
|
||||
"collpass1", "图鉴替换用户",
|
||||
)
|
||||
first = upload_cloud(client, info["token"], cloud_type_id="1").json()["cloud"]
|
||||
second = upload_cloud(client, info["token"], cloud_type_id="1").json()["cloud"]
|
||||
|
||||
r = client.delete(f"/api/v1/clouds/{first['id']}", headers=bearer(info["token"]))
|
||||
assert r.status_code == 200
|
||||
|
||||
r = client.get("/api/v1/collections/me", headers=bearer(info["token"]))
|
||||
assert r.status_code == 200
|
||||
assert len(r.json()) == 1
|
||||
assert r.json()[0]["first_cloud_id"] == second["id"]
|
||||
assert r.json()[0]["first_cloud"]["id"] == second["id"]
|
||||
|
||||
|
||||
def test_batch_delete_removes_affected_collections(client: TestClient, monkeypatch) -> None:
|
||||
info = register_and_confirm(
|
||||
client, monkeypatch,
|
||||
f"coll-batch-{uuid.uuid4().hex[:8]}@example.com",
|
||||
"collpass1", "图鉴批删用户",
|
||||
)
|
||||
first = upload_cloud(client, info["token"], cloud_type_id="1").json()["cloud"]
|
||||
second = upload_cloud(client, info["token"], cloud_type_id="2").json()["cloud"]
|
||||
|
||||
r = client.post(
|
||||
"/api/v1/clouds/batch-delete",
|
||||
headers=bearer(info["token"]),
|
||||
json={"ids": [first["id"], second["id"]]},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
r = client.get("/api/v1/collections/me", headers=bearer(info["token"]))
|
||||
assert r.status_code == 200
|
||||
assert r.json() == []
|
||||
|
||||
Reference in New Issue
Block a user