import os import tempfile import pytest @pytest.fixture(scope="module") def client(): db_path = tempfile.NamedTemporaryFile(suffix=".db", delete=False).name isolation = pytest.MonkeyPatch() isolation.setenv("CACU_DATABASE_URL", f"sqlite:///{db_path}") isolation.setenv("AUTH_LITE_ENABLED", "false") from core.cacu.base import CaCuModel from core.cacu.models import Paciente from persistance.db import get_cacu_engine from persistance.settings import settings isolation.setattr(settings, "cacu_database_url", f"sqlite:///{db_path}") get_cacu_engine.cache_clear() engine = get_cacu_engine() try: CaCuModel.metadata.create_all(engine) from sqlmodel import Session with Session(engine) as session: session.add(Paciente(pac_id_hospital="H-1", pac_sexo="Femenino")) session.commit() from webapi import create_app app = create_app() app.config.update(TESTING=True) with app.test_client() as client: yield client finally: engine.dispose() get_cacu_engine.cache_clear() os.unlink(db_path) isolation.undo() def test_health(client): response = client.get("/health") assert response.status_code == 200 assert response.get_json() == {"status": "ok"} def test_get_paciente(client): response = client.get("/cacu/pacientes/1") assert response.status_code == 200 assert response.get_json()["pac_id_hospital"] == "H-1" def test_get_paciente_not_found(client): response = client.get("/cacu/pacientes/999") assert response.status_code == 404 def test_predict_not_implemented(client): response = client.post("/cacu/predict") assert response.status_code == 501