Spaces:
Sleeping
Sleeping
| import json | |
| from fastapi.testclient import TestClient | |
| from app.main import app | |
| from app.services import annotation_service | |
| from app.services.annotation_service import AnnotationService | |
| def test_hydrate_migrates_legacy_annotation_without_project_id(tmp_path, monkeypatch): | |
| monkeypatch.setattr(annotation_service, "_ANNOT_DIR", str(tmp_path)) | |
| document_id = "doc-1" | |
| row = { | |
| "annotation_id": "ann-1", | |
| "document_id": document_id, | |
| "session_id": "project-from-old-session-field", | |
| "target_snippets": [{"page_number": 1, "text": "important", "boxes": []}], | |
| "note_text": "keep this", | |
| "created_at": 1.0, | |
| "updated_at": 1.0, | |
| } | |
| (tmp_path / f"{document_id}.json").write_text(json.dumps([row]), encoding="utf-8") | |
| service = AnnotationService() | |
| annotations = service.get_for_document(document_id) | |
| assert len(annotations) == 1 | |
| assert annotations[0].project_id == "project-from-old-session-field" | |
| persisted = json.loads((tmp_path / f"{document_id}.json").read_text(encoding="utf-8")) | |
| assert persisted[0]["project_id"] == "project-from-old-session-field" | |
| def test_hydrate_skips_invalid_annotation_rows(tmp_path, monkeypatch): | |
| monkeypatch.setattr(annotation_service, "_ANNOT_DIR", str(tmp_path)) | |
| document_id = "doc-2" | |
| rows = [ | |
| {"annotation_id": "bad", "document_id": document_id, "project_id": "p1"}, | |
| { | |
| "annotation_id": "good", | |
| "document_id": document_id, | |
| "project_id": "p1", | |
| "target_snippets": [{"page_number": 1, "text": "ok", "boxes": []}], | |
| "created_at": 1.0, | |
| "updated_at": 1.0, | |
| }, | |
| ] | |
| (tmp_path / f"{document_id}.json").write_text(json.dumps(rows), encoding="utf-8") | |
| service = AnnotationService() | |
| annotations = service.get_for_document(document_id) | |
| assert [a.annotation_id for a in annotations] == ["good"] | |
| def test_stt_status_route_is_not_captured_as_document_id(monkeypatch): | |
| from app.services.transcription_service import TranscriptionService | |
| class FakeTranscriptionService: | |
| is_available = True | |
| def is_model_loading(self): | |
| return False | |
| monkeypatch.setattr(TranscriptionService, "get", classmethod(lambda cls: FakeTranscriptionService())) | |
| response = TestClient(app).get("/annotations/stt-status") | |
| assert response.status_code == 200 | |
| assert response.json() == {"available": True, "is_loading": False} | |