File size: 2,010 Bytes
56edde7 a8f12f6 56edde7 a8f12f6 56edde7 a8f12f6 56edde7 a8f12f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
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"""
# Create a sample TXT file
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 "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_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 |