File size: 1,692 Bytes
af107f1 | 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 | """
Test cases for PDF Redaction API
"""
import pytest
from fastapi.testclient import TestClient
from pathlib import Path
import sys
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from main import app
client = TestClient(app)
def test_health_check():
"""Test health check endpoint"""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert "model_loaded" in data
def test_root():
"""Test root endpoint"""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
def test_stats():
"""Test stats endpoint"""
response = client.get("/stats")
assert response.status_code == 200
data = response.json()
assert "pending_uploads" in data
assert "processed_files" in data
assert "model_loaded" in data
def test_redact_no_file():
"""Test redaction without file"""
response = client.post("/redact")
assert response.status_code == 422 # Unprocessable entity
def test_redact_wrong_file_type():
"""Test redaction with wrong file type"""
files = {"file": ("test.txt", b"test content", "text/plain")}
response = client.post("/redact", files=files)
assert response.status_code == 400
def test_download_nonexistent():
"""Test downloading non-existent file"""
response = client.get("/download/nonexistent-id")
assert response.status_code == 404
# Add more tests as needed
# - Test with actual PDF file
# - Test with different DPI values
# - Test with entity type filtering
# - Test cleanup functionality
|