Files
motovaultpro/ocr/tests/test_health.py
Eric Gullickson 1ba491144b
Some checks failed
Deploy to Staging / Build Images (pull_request) Successful in 7m41s
Deploy to Staging / Deploy to Staging (pull_request) Failing after 13s
Deploy to Staging / Verify Staging (pull_request) Has been skipped
Deploy to Staging / Notify Staging Ready (pull_request) Has been skipped
Deploy to Staging / Notify Staging Failure (pull_request) Successful in 8s
feat: add OCR service container (refs #64)
Add Python-based OCR service container (mvp-ocr) as the 6th service:
- Python 3.11-slim with FastAPI/uvicorn
- Tesseract OCR with English language pack
- pillow-heif for HEIC image support
- opencv-python-headless for image preprocessing
- Health endpoint at /health
- Unit tests for health, HEIC support, and Tesseract availability

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:06:16 -06:00

53 lines
1.4 KiB
Python

"""Tests for OCR service health and core functionality."""
import io
import pytest
from fastapi.testclient import TestClient
from PIL import Image
from app.main import app
@pytest.fixture
def client():
"""Create test client for FastAPI app."""
return TestClient(app)
def test_health_endpoint(client):
"""Health endpoint returns healthy status."""
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "healthy"}
def test_root_endpoint(client):
"""Root endpoint returns service information."""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["service"] == "mvp-ocr"
assert "version" in data
def test_pillow_heif_can_register():
"""pillow-heif can register with Pillow for HEIC support."""
import pillow_heif
pillow_heif.register_heif_opener()
# Verify HEIC format is registered
assert "HEIF" in Image.registered_extensions().values()
def test_tesseract_available():
"""Tesseract OCR is available and can process images."""
import pytesseract
# Create a simple test image with text
img = Image.new("RGB", (200, 50), color="white")
# Verify pytesseract can call tesseract (will return empty string for blank image)
result = pytesseract.image_to_string(img)
# Just verify it doesn't raise an exception - blank image returns empty/whitespace
assert isinstance(result, str)