Spaces:
Sleeping

studiq-backend / tests /test_notes.py
StudIQ Auto Deploy Daemon
Auto deploy: Tue Oct 27 11:23:50 IST 2026
9f7b159
Raw History Blame Contribute Delete
2.59 kB
"""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