preliminary release

This commit is contained in:
Roberto Treviño Cervantes
2026-10-29 12:12:28 -06:00
parent be9b528c5f
commit f65d5f3f4d
37 changed files with 2139 additions and 228 deletions
+47
View File
@@ -14,6 +14,10 @@ import pytest
# Tests use throwaway SQLite files as "arbitrary SQL sources"; production
# excludes sqlite by default (see webapi.imports.connectors.sql_policy).
os.environ.setdefault("WEBAPI_SQL_ALLOWED_DIALECTS", "sqlite,mysql,mariadb,postgresql,mssql,oracle")
# The import log and the indicator queue write files; keep them out of the tree.
_STATE_DIR = tempfile.mkdtemp(prefix="webapi-tests-")
os.environ.setdefault("WEBAPI_REPORT_DIR", os.path.join(_STATE_DIR, "reportes"))
os.environ.setdefault("INDICADORES_DIR", os.path.join(_STATE_DIR, "indicadores"))
@pytest.fixture(scope="module")
@@ -54,3 +58,46 @@ def _migrate(domain: str) -> None:
ini = Path(persistance.__file__).parent / domain / "alembic.ini"
command.upgrade(Config(str(ini)), "head")
# Indicator-route tests (vendored from the fork's WebApi tests): the kit's
# demonstration database, seeded into a temporary SQLite file per domain.
SEMESTRES = ["2025-S1", "2025-S2"]
MESES = ["2025-01", "2025-02", "2025-03"]
def sembrar_base(proyecto: str, motor) -> None:
"""La base de demostración del kit: staging sintético, carga y todos los indicadores calculados.
Lo mismo que hace `indicadores_kit.tea.fixtures.base_de_prueba` para
TEA: cada definición de `measures_de(proyecto)` queda calculada en los
periodos de 2025 que publica (`SEMESTRES`, y los doce meses si publica
meses).
"""
from indicadores_kit.demostracion import base_de_prueba
base_de_prueba(motor, proyecto)
def cliente_de(proyecto: str, tmp_path_factory):
"""Generador para la fixture `client` de un proyecto: una base SQLite temporal ya sembrada."""
from persistance import db
from persistance.settings import settings
ruta = tmp_path_factory.mktemp(proyecto) / f"{proyecto}.db"
obtener_motor = getattr(db, f"get_{proyecto}_engine")
with pytest.MonkeyPatch.context() as mp:
mp.setattr(settings, f"{proyecto}_database_url", f"sqlite:///{ruta}")
obtener_motor.cache_clear()
try:
sembrar_base(proyecto, obtener_motor())
from webapi import create_app
app = create_app()
app.config.update(TESTING=True)
with app.test_client() as cliente:
yield cliente
finally:
obtener_motor().dispose()
obtener_motor.cache_clear()