File size: 1,175 Bytes
174138d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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