Spaces:
Sleeping
Sleeping
Download tests/test_notes.py from baljot07/studiq-backend: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/tests/test_notes.py
- Command line
-
hf download hf://spaces/baljot07/studiq-backend/tests/test_notes.py
-
curl -L -o test_notes.py https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/tests/test_notes.py
2.59 kB
| """Tests for study notes endpoints.""" | |
| import pytest | |
| from httpx import AsyncClient | |
| from tests.conftest import create_authenticated_user | |
| 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() == [] | |
| 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 | |