diff --git a/backend/tests/test_parse_doc_api.py b/backend/tests/test_parse_doc_api.py deleted file mode 100644 index d2d9c29..0000000 --- a/backend/tests/test_parse_doc_api.py +++ /dev/null @@ -1,73 +0,0 @@ - -from io import BytesIO -import zipfile - -from backend.main import app -from fastapi.testclient import TestClient - -client = TestClient(app) - - -def build_docx(paragraphs: list[str]) -> BytesIO: - document_xml = """ - - - {paras} - - - - - - -""" - paras = "\n".join(f"{paragraph}" for paragraph in paragraphs) - buffer = BytesIO() - with zipfile.ZipFile(buffer, 'w', compression=zipfile.ZIP_DEFLATED) as archive: - archive.writestr('[Content_Types].xml', """ - - - - - -""") - archive.writestr('_rels/.rels', """ - - - -""") - archive.writestr('word/document.xml', document_xml.format(paras=paras)) - buffer.seek(0) - buffer.name = 'sample-report.docx' - return buffer - - -def test_admin_parse_doc_extracts_case_preview_from_docx() -> None: - file_obj = build_docx([ - 'Case ID: 124', - 'Age: 16', - 'Gender: female', - 'Status: analyzed', - 'Found alive: yes', - 'Found distance km: 3.5', - 'Who found: Search team 4', - 'Notes: Found near the logging road', - ]) - - response = client.post( - '/api/v1/admin/parse-doc', - files={'file': ('sample-report.docx', file_obj, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')}, - ) - - assert response.status_code == 200 - payload = response.json() - assert payload['parsed'] is True - assert payload['filename'] == 'sample-report.docx' - assert payload['preview']['case_id'] == '124' - assert payload['preview']['case']['age'] == 16 - assert payload['preview']['case']['gender'] == 'female' - assert payload['preview']['case']['status'] == 'analyzed' - assert payload['preview']['case']['found_alive'] is True - assert payload['preview']['case']['found_distance_km'] == 3.5 - assert payload['preview']['case']['who_found'] == 'Search team 4' - assert payload['preview']['case']['notes'] == 'Found near the logging road' - assert 'Case ID: 124' in payload['raw_text']