Test publication of CaMa demonstration measures
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""Publicación HTTP de CAM-01 y CAM-02 sobre la base sintética del kit."""
|
||||
import pytest
|
||||
from conftest import cliente_de
|
||||
|
||||
IDS = {"cama_tasa_deteccion_histopatologica": "C1", "cama_dias_resultado_diagnostico": "C3r"}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def client(tmp_path_factory):
|
||||
yield from cliente_de("cama", tmp_path_factory)
|
||||
|
||||
|
||||
def test_catalogo_publica_las_dos_medidas(client):
|
||||
catalogo = {item["id"]: item for item in client.get("/cama/indicadores").get_json()}
|
||||
for identificador, contrato in IDS.items():
|
||||
assert catalogo[identificador]["contrato"] == contrato
|
||||
assert "sintética" in catalogo[identificador]["titulo"]
|
||||
assert set(catalogo[identificador]["tipos_periodo"]) == {"mes", "semestre"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("indicador,contrato", IDS.items())
|
||||
def test_periodos_metadatos_y_datos(client, indicador, contrato):
|
||||
raiz = f"/cama/indicadores/{indicador}"
|
||||
assert client.get(raiz + "/metadatos").status_code == 200
|
||||
assert client.get(raiz + "/periodos").status_code == 200
|
||||
response = client.get(raiz + "/datos?periodos=2025-S1")
|
||||
assert response.status_code == 200 and response.is_json
|
||||
data = response.get_json()
|
||||
assert data["contrato"] == contrato and data["periodos"] == ["2025-S1"]
|
||||
assert isinstance(data["filas"], list) and data["filas"]
|
||||
assert client.get(raiz + "/datos?periodos=2025-13").status_code == 404
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def client_sin_supresion(tmp_path_factory):
|
||||
from indicadores_kit.demostracion import base_de_prueba
|
||||
from indicadores_kit.registry.parametros import RUTA_PARAMETROS
|
||||
from persistance import db
|
||||
from persistance.settings import settings
|
||||
from webapi import create_app
|
||||
|
||||
carpeta = tmp_path_factory.mktemp("cama_f4b2")
|
||||
parametros = carpeta / "parametros.toml"
|
||||
parametros.write_text(RUTA_PARAMETROS.read_text(encoding="utf-8").replace("valor = 5", "valor = 1"), encoding="utf-8")
|
||||
with pytest.MonkeyPatch.context() as mp:
|
||||
mp.setattr(settings, "cama_database_url", f"sqlite:///{carpeta / 'demo.db'}")
|
||||
db.get_cama_engine.cache_clear()
|
||||
try:
|
||||
base_de_prueba(db.get_cama_engine(), "cama", ruta_parametros=parametros)
|
||||
yield create_app().test_client()
|
||||
finally:
|
||||
db.get_cama_engine().dispose()
|
||||
db.get_cama_engine.cache_clear()
|
||||
|
||||
|
||||
def test_valores_sinteticos_visibles_con_umbral_de_prueba(client_sin_supresion):
|
||||
raiz = "/cama/indicadores/"
|
||||
c1 = client_sin_supresion.get(raiz + "cama_tasa_deteccion_histopatologica/datos?periodos=2025-S1").get_json()
|
||||
c3 = client_sin_supresion.get(raiz + "cama_dias_resultado_diagnostico/datos?periodos=2025-S1").get_json()
|
||||
assert c1["filas"][0]["numerador"] == 0 and c1["filas"][0]["denominador"] == 1
|
||||
assert c1["filas"][0]["valor"] == 0 and c1["filas"][0]["ic_alto"] > 0
|
||||
fila = c3["filas"][0]
|
||||
assert (fila["n"], fila["q1"], fila["mediana"], fila["q3"]) == (4, 2.25, 6.5, 12.5)
|
||||
assert fila["n_excluido"] == 1 and fila["unidad"] == "dias"
|
||||
Reference in New Issue
Block a user