Spaces:
Sleeping
Sleeping
File size: 2,586 Bytes
2026abe 9f7b159 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | """Tests for study notes endpoints."""
import pytest
from httpx import AsyncClient
from tests.conftest import create_authenticated_user
@pytest.mark.asyncio
async def test_study_notes_crud(client: AsyncClient):
user_id, token = await create_authenticated_user(client)
headers = {"Authorization": f"Bearer {token}"}
# 1. Create a note
res = await client.post(
"/api/v1/notes",
json={
"content": "Newton's Second Law: F = ma",
"topic_name": "Dynamics",
"subject_name": "Physics",
"bookmarked": True,
},
headers=headers,
)
assert res.status_code == 201
data = res.json()
note_id = data["id"]
assert data["content"] == "Newton's Second Law: F = ma"
assert data["bookmarked"] is True
# 2. List notes
list_res = await client.get("/api/v1/notes", headers=headers)
assert list_res.status_code == 200
notes = list_res.json()
assert len(notes) == 1
assert notes[0]["id"] == note_id
# 3. Toggle bookmark
bm_res = await client.patch(f"/api/v1/notes/{note_id}/bookmark", headers=headers)
assert bm_res.status_code == 200
assert bm_res.json()["bookmarked"] is False
# 4. Delete all notes
del_res = await client.delete("/api/v1/notes", headers=headers)
assert del_res.status_code == 200
assert del_res.json()["deleted"] is True
# 5. List after delete all
list_res2 = await client.get("/api/v1/notes", headers=headers)
assert list_res2.status_code == 200
assert list_res2.json() == []
@pytest.mark.asyncio
async def test_delete_single_note(client: AsyncClient):
user_id, token = await create_authenticated_user(client)
headers = {"Authorization": f"Bearer {token}"}
# 1. Create two notes
res1 = await client.post(
"/api/v1/notes",
json={"content": "Note 1", "topic_name": "T1", "subject_name": "S1"},
headers=headers,
)
res2 = await client.post(
"/api/v1/notes",
json={"content": "Note 2", "topic_name": "T2", "subject_name": "S2"},
headers=headers,
)
id1 = res1.json()["id"]
id2 = res2.json()["id"]
# 2. Delete single note
del_res = await client.delete(f"/api/v1/notes/{id1}", headers=headers)
assert del_res.status_code == 200
assert del_res.json()["deleted"] is True
# 3. Verify only id2 remains
list_res = await client.get("/api/v1/notes", headers=headers)
assert list_res.status_code == 200
notes = list_res.json()
assert len(notes) == 1
assert notes[0]["id"] == id2
|