everycure-ner-pdf / tests /test_api.py
Luis Chaves
moved things around, cleaned up files, final debug of dokcerfile
70b960d
raw
history blame
1.19 kB
import pytest
from fastapi.testclient import TestClient
from everycure.app import app
import os
import tempfile
client = TestClient(app)
def create_test_pdf():
# Create a temporary PDF file for testing
with tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) as tmp:
tmp.write(b"%PDF-1.5\nTest PDF content")
return tmp.name
@pytest.fixture
def test_pdf():
pdf_path = create_test_pdf()
yield pdf_path
# Cleanup after test
os.unlink(pdf_path)
def test_extract_entities_invalid_file():
# Test with non-PDF file
with tempfile.NamedTemporaryFile(suffix=".txt") as tmp:
tmp.write(b"Not a PDF file")
tmp.seek(0)
response = client.post(
"/api/v1/extract",
files={"file": ("test.txt", tmp, "text/plain")}
)
assert response.status_code == 415
assert "Unsupported file type." in response.json()["detail"]
def test_extract_entities_empty_file(test_pdf):
with open(test_pdf, "rb") as f:
response = client.post(
"/api/v1/extract",
files={} # No file provided
)
assert response.status_code == 400 # FastAPI's validation error