dots-ocr-idcard / tests /test_app.py
tommulder's picture
feat(api): fast FastAPI app + model loader refactor; add mock mode for tests\n\n- Add pyproject + setuptools config and console entrypoint\n- Implement enhanced field extraction + MRZ heuristics\n- Add response builder with compatibility for legacy MRZ fields\n- New preprocessing pipeline for PDFs/images\n- HF Spaces GPU: cache ENV, optional flash-attn, configurable base image\n- Add Make targets for Spaces GPU and local CPU\n- Add httpx for TestClient; tests pass in mock mode\n- Remove embedded model files and legacy app/modules
211e423
raw
history blame
1.12 kB
"""Tests for the main FastAPI application."""
import pytest
from fastapi.testclient import TestClient
from src.kybtech_dots_ocr.app import app
client = TestClient(app)
def test_health_check():
"""Test the health check endpoint."""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert "status" in data
assert "version" in data
def test_ocr_endpoint_missing_file():
"""Test OCR endpoint with missing file."""
response = client.post("/v1/id/ocr")
assert response.status_code == 422 # Validation error
def test_ocr_endpoint_invalid_file():
"""Test OCR endpoint with invalid file."""
files = {"file": ("test.txt", b"not an image", "text/plain")}
response = client.post("/v1/id/ocr", files=files)
# Should handle gracefully
assert response.status_code in [400, 422, 500]
@pytest.mark.skip(reason="Requires model to be loaded")
def test_ocr_endpoint_with_image():
"""Test OCR endpoint with actual image (requires model)."""
# This test would require the model to be loaded
# and actual image data
pass