Files
WebApi/tests/test_app.py
T
Roberto Treviño Cervantes c1444e2b8d initial commit
2026-09-21 10:23:40 -06:00

55 lines
1.3 KiB
Python

import os
import tempfile
import pytest
@pytest.fixture(scope="module")
def client():
db_path = tempfile.NamedTemporaryFile(suffix=".db", delete=False).name
os.environ["CACU_DATABASE_URL"] = f"sqlite:///{db_path}"
from core.cacu.base import CaCuModel
from core.cacu.models import Paciente
from persistance.db import get_cacu_engine
engine = get_cacu_engine()
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
os.unlink(db_path)
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