Text-to-Document-Generation/PDF-Redaction-API
0
1"""2Test cases for PDF Redaction API3"""4import pytest5from fastapi.testclient import TestClient6from pathlib import Path7import sys8 9# Add parent directory to path10sys.path.insert(0, str(Path(__file__).parent.parent))11 12from main import app13 14client = TestClient(app)15 16 17def test_health_check():18 """Test health check endpoint"""19 response = client.get("/health")20 assert response.status_code == 20021 data = response.json()22 assert data["status"] == "healthy"23 assert "model_loaded" in data24 25 26def test_root():27 """Test root endpoint"""28 response = client.get("/")29 assert response.status_code == 20030 data = response.json()31 assert data["status"] == "healthy"32 33 34def test_stats():35 """Test stats endpoint"""36 response = client.get("/stats")37 assert response.status_code == 20038 data = response.json()39 assert "pending_uploads" in data40 assert "processed_files" in data41 assert "model_loaded" in data42 43 44def test_redact_no_file():45 """Test redaction without file"""46 response = client.post("/redact")47 assert response.status_code == 422 # Unprocessable entity48 49 50def test_redact_wrong_file_type():51 """Test redaction with wrong file type"""52 files = {"file": ("test.txt", b"test content", "text/plain")}53 response = client.post("/redact", files=files)54 assert response.status_code == 40055 56 57def test_download_nonexistent():58 """Test downloading non-existent file"""59 response = client.get("/download/nonexistent-id")60 assert response.status_code == 40461 62 63# Add more tests as needed64# - Test with actual PDF file65# - Test with different DPI values66# - Test with entity type filtering67# - Test cleanup functionality68 