| from fastapi.testclient import TestClient |
| from src.main import app |
| from io import BytesIO |
|
|
| client = TestClient(app) |
|
|
| def test_coding_endpoint(): |
| """Test existing text input endpoint""" |
| provider_notes = { |
| "provider_notes": "Patient has a fever and cough." |
| } |
| |
| response = client.post("/api/coding", json=provider_notes) |
| |
| assert response.status_code == 200 |
| data = response.json() |
| |
| assert "cpt_codes" in data |
| assert "icd_codes" in data |
| assert isinstance(data["cpt_codes"], list) |
| assert isinstance(data["icd_codes"], list) |
|
|
|
|
| def test_file_upload_endpoint(): |
| """Test new file upload endpoint""" |
| file_content = b"Patient John Doe presents with acute bronchitis. Cough for 5 days, productive with yellow sputum. Lung exam reveals diffuse wheezing." |
| |
| files = { |
| "file": ("provider_notes.txt", BytesIO(file_content), "text/plain") |
| } |
| |
| response = client.post("/api/upload-file", files=files) |
| |
| assert response.status_code == 200 |
| data = response.json() |
| |
| assert data["success"] is True |
| assert data["filename"] == "provider_notes.txt" |
| assert data["extracted_text_length"] > 0 |
| assert "pii_removed" in data |
| assert "pii_count" in data |
| assert "cpt_codes" in data |
| assert "icd_codes" in data |
|
|
|
|
| def test_file_upload_with_pii(): |
| """Test file upload with PII - should be removed""" |
| file_content = b""" |
| Patient: John Doe |
| DOB: 01/15/1980 |
| Phone: 555-123-4567 |
| Address: 123 Main St, New York, NY |
| |
| Chief Complaint: Chest pain |
| History: Patient presents with acute chest pain... |
| """ |
| |
| files = { |
| "file": ("notes_with_pii.txt", BytesIO(file_content), "text/plain") |
| } |
| |
| response = client.post("/api/upload-file", files=files) |
| |
| assert response.status_code == 200 |
| data = response.json() |
| |
| |
| assert data["pii_removed"] is True |
| assert data["pii_count"] > 0 |
|
|
|
|
| def test_file_upload_invalid_extension(): |
| """Test file upload with invalid file type""" |
| file_content = b"Some content" |
| |
| files = { |
| "file": ("document.pdf", BytesIO(file_content), "application/pdf") |
| } |
| |
| response = client.post("/api/upload-file", files=files) |
| |
| assert response.status_code == 400 |
|
|
|
|
| def test_file_upload_empty_file(): |
| """Test file upload with empty file""" |
| file_content = b"" |
| |
| files = { |
| "file": ("empty.txt", BytesIO(file_content), "text/plain") |
| } |
| |
| response = client.post("/api/upload-file", files=files) |
| |
| assert response.status_code == 400 |