import pytest from httpx import AsyncClient @pytest.fixture async def auth_headers(client: AsyncClient): resp = await client.post("/api/v1/auth/register", json={ "email": "pdfuser@example.com", "username": "pdfuser", "password": "testpass123", }) assert resp.status_code == 201 return {"Authorization": f"Bearer {resp.json()['access_token']}"} async def test_compile_pdf(client: AsyncClient, auth_headers: dict): resp = await client.post("/api/v1/pdf/compile", json={ "title": "My Health Report", }, headers=auth_headers) assert resp.status_code == 201 data = resp.json() assert data["title"] == "My Health Report" async def test_list_pdfs(client: AsyncClient, auth_headers: dict): await client.post("/api/v1/pdf/compile", json={"title": "Test"}, headers=auth_headers) resp = await client.get("/api/v1/pdf/", headers=auth_headers) assert resp.status_code == 200 assert len(resp.json()["pdfs"]) >= 1 async def test_pdf_ownership_isolation(client: AsyncClient, auth_headers: dict): resp = await client.post("/api/v1/pdf/compile", json={"title": "Private"}, headers=auth_headers) pdf_id = resp.json()["id"] resp2 = await client.post("/api/v1/auth/register", json={ "email": "pdfother@example.com", "username": "pdfother", "password": "testpass123", }) other_headers = {"Authorization": f"Bearer {resp2.json()['access_token']}"} resp = await client.get(f"/api/v1/pdf/{pdf_id}/download", headers=other_headers) assert resp.status_code == 404