absorb Orquestacion into webapi.orquestacion
Orquestacion was a separate uv package with exactly one consumer (webapi.indicadores_vivos) and no independent deployment: the Dockerfile already copied it straight into this image and ran one uv sync for everything. Folding it in removes a redundant pyproject.toml/uv.lock/venv without losing the standalone CLI (python -m webapi.orquestacion ciclo/ confirmar-riesgos) or its test suite, which now runs as part of this project's own pytest run. 417 tests pass (416 unchanged + the merged orquestacion suite); verified live in a built image, where the indicadores worker completed a full cacu/cama/tea cycle against webapi.orquestacion.ejecutor.
This commit is contained in:
@@ -4,12 +4,25 @@
|
||||
`persistance.db.get_<domain>_engine` functions are `@lru_cache`d, so changing
|
||||
`<DOMAIN>_DATABASE_URL` alone has no effect once an engine exists.
|
||||
`wire_domain` resets all three (env var, singleton, cache).
|
||||
|
||||
The `base`/`base_de` family (below `ANIO`) is for `webapi.orquestacion`:
|
||||
una base del dominio por prueba, migrada por el paso `migrar`, con el staging
|
||||
sintético del kit.
|
||||
"""
|
||||
import os
|
||||
import tempfile
|
||||
from dataclasses import dataclass, replace
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlmodel import Session
|
||||
|
||||
from indicadores_kit.registry.parametros import RUTA_PARAMETROS
|
||||
from webapi.orquestacion import Contexto, correr
|
||||
from webapi.orquestacion.conexion import apuntar
|
||||
from webapi.orquestacion.repositorios import repositorios_de
|
||||
|
||||
# Tests use throwaway SQLite files as "arbitrary SQL sources"; production
|
||||
# excludes sqlite by default (see webapi.imports.connectors.sql_policy).
|
||||
@@ -19,6 +32,58 @@ _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"))
|
||||
|
||||
ANIO = 2025
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Base:
|
||||
"""El proyecto, su contexto (con los repositorios de Persistance) y su dominio en Persistance."""
|
||||
|
||||
proyecto: str
|
||||
ctx: Contexto
|
||||
dominio: object
|
||||
motor: object
|
||||
|
||||
def correr(self, *pasos: str, **cambios) -> dict:
|
||||
"""Corre estos pasos (en el orden del ciclo) con el contexto cambiado. Devuelve el resumen de cada una."""
|
||||
return {p.nombre: p.resumen for p in correr(replace(self.ctx, **cambios), solo=pasos)}
|
||||
|
||||
def staging(self):
|
||||
"""Una sesión sobre la base, para cambiar el staging como lo haría la ingesta."""
|
||||
return Session(self.motor)
|
||||
|
||||
|
||||
def base_de(proyecto: str, carpeta) -> Base:
|
||||
url = f"sqlite:///{carpeta / f'{proyecto}.db'}"
|
||||
apuntar(proyecto, url)
|
||||
ctx = Contexto(proyecto, ANIO, ANIO, repos=repositorios_de(proyecto))
|
||||
correr(ctx, solo=["migrar"])
|
||||
motor = create_engine(url)
|
||||
with Session(motor) as sesion:
|
||||
import_module(f"indicadores_kit.{proyecto}.fixtures").insertar(sesion)
|
||||
sesion.commit()
|
||||
return Base(proyecto, ctx, import_module(f"persistance.{proyecto}"), motor)
|
||||
|
||||
|
||||
@pytest.fixture(params=["cacu", "cama", "tea"])
|
||||
def proyecto(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def base(proyecto, tmp_path):
|
||||
base = base_de(proyecto, tmp_path)
|
||||
yield base
|
||||
base.motor.dispose()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sin_supresion(tmp_path):
|
||||
"""`parametros.toml` con umbral de supresión 1, para ver los conteos pequeños del fixture."""
|
||||
ruta = tmp_path / "parametros.toml"
|
||||
ruta.write_text(RUTA_PARAMETROS.read_text(encoding="utf-8").replace("valor = 5", "valor = 1"), encoding="utf-8")
|
||||
return ruta
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def wire_domain():
|
||||
|
||||
Reference in New Issue
Block a user