everycure-ner-pdf / tests /test_api.py
Luis Chaves
debugging cuda issues and adding basic tests for api
174138d
raw
history blame
1.18 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(
"/extract",
files={"file": ("test.txt", tmp, "text/plain")}
)
assert response.status_code == 400
assert "Invalid file type" in response.json()["detail"]
def test_extract_entities_empty_file(test_pdf):
with open(test_pdf, "rb") as f:
response = client.post(
"/extract",
files={} # No file provided
)
assert response.status_code == 422 # FastAPI's validation error