Pruebas con todos los indicadores de CaCu y CaMa, como en TEA
La base de prueba es la de demostración del kit (todas las definiciones calculadas en los periodos que publican) y hay una prueba de figura por indicador. El caso del mes sin reporte pasa a 2024-11: 2025-11 ya tiene. Pruebas: WebApi 79 passed. CSO5.5
This commit is contained in:
+7
-38
@@ -1,53 +1,22 @@
|
|||||||
"""Lo común de las pruebas de indicadores de CaCu y CaMa."""
|
"""Lo común de las pruebas de indicadores de CaCu y CaMa."""
|
||||||
|
|
||||||
from importlib import import_module
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from sqlmodel import Session, select
|
|
||||||
|
|
||||||
SEMESTRES = ["2025-S1", "2025-S2"]
|
SEMESTRES = ["2025-S1", "2025-S2"]
|
||||||
MESES = ["2025-01", "2025-02", "2025-03"]
|
MESES = ["2025-01", "2025-02", "2025-03"]
|
||||||
|
|
||||||
|
|
||||||
def sembrar_base(proyecto: str, motor) -> None:
|
def sembrar_base(proyecto: str, motor) -> None:
|
||||||
"""Staging sintético del kit, tablas del kit, carga y el indicador de ejemplo calculado.
|
"""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,
|
Lo mismo que hace `indicadores_kit.tea.fixtures.base_de_prueba` para
|
||||||
con los pasos del kit: parámetros, `dim_periodo` (semestres y meses de
|
TEA: cada definición de `measures_de(proyecto)` queda calculada en los
|
||||||
2025) y `<proyecto>_eu8` en `SEMESTRES` y `MESES`.
|
periodos de 2025 que publica (`SEMESTRES`, y los doce meses si publica
|
||||||
|
meses).
|
||||||
"""
|
"""
|
||||||
from indicadores_kit.esquema import crear_esquema
|
from indicadores_kit.demostracion import base_de_prueba
|
||||||
from indicadores_kit.mart.calculo import calcular_measure
|
|
||||||
from indicadores_kit.registry.measures import leer_measure, ruta_de_measure
|
|
||||||
from indicadores_kit.registry.parametros import RUTA_PARAMETROS, cargar_parametros
|
|
||||||
from indicadores_kit.registry.periodos import generar_dim_periodo
|
|
||||||
from indicadores_kit.tablas import tablas_de
|
|
||||||
|
|
||||||
fixtures = import_module(f"indicadores_kit.{proyecto}.fixtures")
|
base_de_prueba(motor, proyecto)
|
||||||
etl = import_module(f"indicadores_kit.{proyecto}.etl")
|
|
||||||
base = import_module(f"core.{proyecto}.base")
|
|
||||||
modelos = import_module(f"core.{proyecto}.models")
|
|
||||||
tablas = tablas_de(proyecto)
|
|
||||||
|
|
||||||
getattr(base, "CaCuModel" if proyecto == "cacu" else "CaMaModel").metadata.create_all(motor)
|
|
||||||
crear_esquema(motor, proyecto)
|
|
||||||
cargar, tabla = (
|
|
||||||
(etl.cargar_citologias, modelos.CitologiaCervical)
|
|
||||||
if proyecto == "cacu"
|
|
||||||
else (etl.cargar_mastografias, modelos.Mastografia)
|
|
||||||
)
|
|
||||||
with Session(motor) as sesion:
|
|
||||||
fixtures.insertar(sesion)
|
|
||||||
cargar(
|
|
||||||
sesion,
|
|
||||||
sesion.exec(select(modelos.Paciente)).all(),
|
|
||||||
sesion.exec(select(tabla)).all(),
|
|
||||||
)
|
|
||||||
cargar_parametros(sesion, RUTA_PARAMETROS, tablas=tablas)
|
|
||||||
generar_dim_periodo(sesion, 2025, 2025, tablas=tablas, tipos=("semestre", "mes"))
|
|
||||||
medida = leer_measure(ruta_de_measure(proyecto, f"{proyecto}_eu8"))
|
|
||||||
for periodo in SEMESTRES + MESES:
|
|
||||||
calcular_measure(sesion, medida, periodo, tablas=tablas, permitir_sin_definir=True)
|
|
||||||
|
|
||||||
|
|
||||||
def cliente_de(proyecto: str, tmp_path_factory):
|
def cliente_de(proyecto: str, tmp_path_factory):
|
||||||
|
|||||||
+13
-1
@@ -89,7 +89,7 @@ def test_figura_con_parametros_mal_formados_da_400(client, query):
|
|||||||
(INDICADOR, "fig_no_existe", ""),
|
(INDICADOR, "fig_no_existe", ""),
|
||||||
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-11"), # un mes sin reporte
|
(INDICADOR, FIGURA, "?periodos=2024-11"), # un mes sin reporte
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
||||||
@@ -108,3 +108,15 @@ def test_un_keyerror_interno_no_se_vuelve_404(client, monkeypatch):
|
|||||||
monkeypatch.setattr(indicadores, "figura_json", falla)
|
monkeypatch.setattr(indicadores, "figura_json", falla)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
_figura(client, query="?periodos=2025-S1")
|
_figura(client, query="?periodos=2025-S1")
|
||||||
|
|
||||||
|
|
||||||
|
# --- Todos los indicadores del proyecto ---
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_figura_de_cada_indicador(client, indicador):
|
||||||
|
for figura in figuras_de(DEFINICIONES[indicador]):
|
||||||
|
response = _figura(client, indicador, figura)
|
||||||
|
|
||||||
|
assert response.status_code == 200, (indicador, figura)
|
||||||
|
assert set(response.get_json()) >= {"data", "layout"}
|
||||||
|
|||||||
+13
-1
@@ -89,7 +89,7 @@ def test_figura_con_parametros_mal_formados_da_400(client, query):
|
|||||||
(INDICADOR, "fig_no_existe", ""),
|
(INDICADOR, "fig_no_existe", ""),
|
||||||
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-11"), # un mes sin reporte
|
(INDICADOR, FIGURA, "?periodos=2024-11"), # un mes sin reporte
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
||||||
@@ -108,3 +108,15 @@ def test_un_keyerror_interno_no_se_vuelve_404(client, monkeypatch):
|
|||||||
monkeypatch.setattr(indicadores, "figura_json", falla)
|
monkeypatch.setattr(indicadores, "figura_json", falla)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
_figura(client, query="?periodos=2025-S1")
|
_figura(client, query="?periodos=2025-S1")
|
||||||
|
|
||||||
|
|
||||||
|
# --- Todos los indicadores del proyecto ---
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_figura_de_cada_indicador(client, indicador):
|
||||||
|
for figura in figuras_de(DEFINICIONES[indicador]):
|
||||||
|
response = _figura(client, indicador, figura)
|
||||||
|
|
||||||
|
assert response.status_code == 200, (indicador, figura)
|
||||||
|
assert set(response.get_json()) >= {"data", "layout"}
|
||||||
|
|||||||
Reference in New Issue
Block a user