d156bf3c99
The CaCu catalog holds fourteen measures. A fixture adds H-007, who goes the whole route in order, and a test pins the population, the cases and the median of each of the five new times.
99 lines
3.9 KiB
Python
99 lines
3.9 KiB
Python
"""Los pasos de oro sobre la base del dominio: el registro y las definiciones (el catálogo, del manifiesto de dbt).
|
|
|
|
Vienen del kit (`test_pasos` y `test_produccion`, MD-16). El reporte se lee por los
|
|
repositorios de Persistance, como lo leería `WebApi`.
|
|
"""
|
|
|
|
from datetime import date
|
|
|
|
import pytest
|
|
|
|
from webapi.orchestration.silver.loads import tablas_de_staging
|
|
from webapi.orchestration.reference.age_groups import grupos_de_cortes
|
|
from webapi.orchestration.reference.rules import RUTA_PARAMETROS, valores_del_archivo
|
|
from webapi.orchestration.reference.periods import periodos_de_tipos
|
|
from webapi.orchestration.tables import tablas_de
|
|
from webapi.orchestration.project import period_types
|
|
|
|
from conftest import ANIO
|
|
|
|
# El indicador de ejemplo, su grupo total y lo que da: {periodo: (denominador, numerador)}.
|
|
def cargas(proyecto) -> tuple[str, ...]:
|
|
"""El paso que lleva el staging a la plata (staging directo, T-20c)."""
|
|
return ("load",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_el_registro_se_puede_repetir_y_agrega_los_periodos_que_faltan(base):
|
|
base.run("registry")
|
|
base.run("registry", year_from=ANIO - 1)
|
|
|
|
tablas = tablas_de(base.proyecto)
|
|
esperados = periodos_de_tipos(period_types(base.proyecto, base.ctx.dbt_manifest), ANIO - 1, ANIO, tablas=tablas)
|
|
assert base.dominio.dim_periodo_repository.count() == len(esperados)
|
|
assert base.dominio.measure_report_repository.count() == 0
|
|
|
|
|
|
def test_el_registro_llena_dim_fecha_y_dim_grupo_edad_desde_los_toml(base):
|
|
"""I-MD27 (T-24f): de `comun.dim_fecha.desde` al fin del último año, y los grupos de `<proyecto>.grupos_edad`."""
|
|
base.run("registry")
|
|
base.run("registry", year_to=ANIO + 1) # repetir deja la tabla igual, con el año nuevo
|
|
|
|
valores = valores_del_archivo(RUTA_PARAMETROS)
|
|
desde = date.fromisoformat(valores["comun.dim_fecha.desde"])
|
|
fechas = base.dominio.dim_fecha_repository
|
|
hasta = date(max(ANIO + 1, date.today().year), 12, 31) # o el año del corte (hoy), si es mayor
|
|
assert fechas.count() == (hasta - desde).days + 1
|
|
grupos = [g.etiqueta for g in base.dominio.dim_grupo_edad_repository.list(limit=100)]
|
|
cortes = valores.get(f"{base.proyecto}.grupos_edad")
|
|
esperados = [] if cortes is None else [g.etiqueta for g in grupos_de_cortes(cortes, tablas=tablas_de(base.proyecto))]
|
|
assert sorted(grupos) == sorted(esperados) # TEA no tiene cortes: vacía
|
|
|
|
|
|
|
|
|
|
def test_un_archivo_de_parametros_invalido_no_toca_el_registro(base, tmp_path):
|
|
base.run("registry")
|
|
periodos = base.dominio.dim_periodo_repository.count()
|
|
malo = tmp_path / "malo.toml"
|
|
malo.write_text('[comun.x]\nvalor = 1\nestado = "provisional"\n', encoding="utf-8")
|
|
|
|
with pytest.raises(ValueError, match="fuente"):
|
|
base.run("registry", year_from=ANIO - 1, year_to=ANIO + 1, parameters=malo)
|
|
|
|
assert base.dominio.def_parametro_repository.get("comun.x") is None
|
|
assert base.dominio.def_parametro_repository.get("comun.umbral_supresion") is not None
|
|
assert base.dominio.dim_periodo_repository.count() == periodos
|
|
|
|
|
|
def test_las_definiciones_son_las_del_manifiesto_de_dbt(base):
|
|
"""Pins down: `definitions` seeds the publication catalog from dbt's manifest, once. Fails if a stratum or a
|
|
measure the manifest declares stops reaching `cat_estrato` and `cat_measure`, or a second run deletes rows."""
|
|
resumen = base.run("definitions")["definitions"]
|
|
|
|
# CaCu: three strata and its fourteen measures; CaMa: the BI-RADS stratum of the histopathological result and its
|
|
# eleven measures; TEA: the age group and its ten measures.
|
|
assert resumen["definitions"] == {"cacu": 17, "cama": 12, "tea": 11}[base.proyecto]
|
|
# Y el catálogo de publicación de §6f (T-19b): un `cat_measure` por measure, sincronizado.
|
|
assert base.dominio.cat_measure_repository.count() == {"cacu": 14, "cama": 11, "tea": 10}[base.proyecto]
|
|
assert base.run("definitions")["definitions"]["borradas"] == 0
|
|
|
|
|
|
|
|
|
|
|
|
|