Spaces:
Sleeping
Sleeping
| """HTTP contract for partner link accept: profile payload matches list endpoint (UI cache sync).""" | |
| from __future__ import annotations | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| _SEED = Path(__file__).resolve().parent.parent / "deploy/hf/seed/hf_bundled_store.db" | |
| def api_client(tmp_path, monkeypatch): | |
| assert _SEED.is_file(), f"Missing seed DB: {_SEED}" | |
| dest = tmp_path / "partner_link_store.db" | |
| shutil.copyfile(_SEED, dest) | |
| monkeypatch.setenv("KINK_STORE_PATH", str(dest)) | |
| monkeypatch.setenv("KINK_SKIP_HEAVY_WARM", "1") | |
| monkeypatch.setenv("KINK_HF_REQUIRE_FULL_CATALOG", "0") | |
| sys.modules.pop("api", None) | |
| import api as api_mod | |
| api_mod._backend_impl = None | |
| api_mod._get_backend() | |
| return api_mod | |
| def _headers(token: str) -> dict[str, str]: | |
| return {"x-private-token": token} | |
| def test_accept_partner_request_user_payload_matches_partner_groups_get(api_client) -> None: | |
| """Accept response embeds the same partner_groups as GET /partner-groups (requester refetch UX).""" | |
| client = TestClient(api_client.app) | |
| a = client.post("/users", json={}).json() | |
| b = client.post("/users", json={}).json() | |
| assert client.post( | |
| f"/users/{a['id']}/partners", | |
| headers=_headers(a["private_token"]), | |
| json={"partner_id": b["id"]}, | |
| ).status_code == 200 | |
| accept = client.post( | |
| f"/users/{b['id']}/partner-requests/accept", | |
| headers=_headers(b["private_token"]), | |
| json={"from_user_id": a["id"]}, | |
| ) | |
| assert accept.status_code == 200 | |
| body = accept.json() | |
| assert a["id"] in body.get("partners", []) | |
| listed = client.get( | |
| f"/users/{b['id']}/partner-groups", | |
| headers=_headers(b["private_token"]), | |
| ).json() | |
| assert body.get("partner_groups") == listed.get("items") | |