lexia / tests /test_api.py
davidhf2026's picture
chore: establish LexIA baseline on Windows
c349d51
Raw History Blame Contribute Delete
2.3 kB
import pytest
fastapi = pytest.importorskip("fastapi")
pytest.importorskip("httpx")
from fastapi import FastAPI # noqa: E402
from fastapi.testclient import TestClient # noqa: E402
@pytest.fixture()
def cliente(tmp_path, monkeypatch):
monkeypatch.setenv("LEXIA_RUNTIME", str(tmp_path / "rt"))
monkeypatch.setenv("LEXIA_PLATFORM", "windows-x86_64")
import importlib
from pathlib import Path
from lexia.core import paths as modulo_paths
importlib.reload(modulo_paths)
from lexia.core import config as modulo_config
importlib.reload(modulo_config)
from lexia.setup import service as modulo_service
importlib.reload(modulo_service)
from lexia.api import routes as modulo_rutas
importlib.reload(modulo_rutas)
panel = Path(modulo_rutas.__file__).resolve().parent.parent / "static" / "index.html"
app = FastAPI()
servicio = modulo_service.SetupService(modulo_paths.ensure_runtime())
modulo_rutas.register(app, servicio, status_provider=lambda: {"robot": "IDLE"}, panel=panel)
return TestClient(app)
def test_health_declara_que_no_esta_aprobada_para_publico(cliente):
datos = cliente.get("/api/health").json()
assert datos["app"] == "lexia"
assert datos["approved_for_public_use"] is False
assert datos["phase"] == "not_started"
def test_preflight_responde_sin_descargar(cliente):
datos = cliente.get("/api/setup/preflight").json()
assert datos["platform"] == "windows-x86_64"
assert "free_disk_gib" in datos
def test_el_panel_se_sirve_en_la_raiz(cliente):
assert cliente.get("/").status_code == 200
def test_los_ajustes_nunca_exponen_el_token(cliente):
datos = cliente.get("/api/settings").json()
assert datos["admin"]["token"] in {"", "***"}
def test_un_ajuste_invalido_devuelve_422_y_no_se_aplica(cliente):
respuesta = cliente.patch("/api/settings", json={"llm": {"endpoint": "http://10.0.0.5:8080"}})
assert respuesta.status_code == 422
assert cliente.get("/api/settings").json()["llm"]["endpoint"].startswith("http://127.0.0.1")
def test_un_ajuste_valido_se_aplica(cliente):
respuesta = cliente.patch("/api/settings", json={"voice": {"silence_ms": 700}})
assert respuesta.status_code == 200
assert respuesta.json()["voice"]["silence_ms"] == 700