Files
WebApi/tests/test_orquestacion_timeline.py
T

42 lines
1.7 KiB
Python

"""The timeline repository wired by `repositorios_de` reads the same rows as the kit, in each project."""
from datetime import date, datetime, timedelta, timezone
from importlib import import_module
from indicadores_kit.oro.cohortes.armado import filas_de_linea
from indicadores_kit.tablas import tablas_de
from sqlmodel import Session
CORTE = date(2025, 12, 31)
def kit_rows(base, **filters):
fuentes = import_module(f"indicadores_kit.{base.proyecto}.linea_de_tiempo").FUENTES_PLATA
with Session(base.motor) as session:
return filas_de_linea(session, tablas_de(base.proyecto), fuentes, **filters)
def test_the_whole_timeline_matches_the_kit(base):
base.correr("catalogos", "cargar")
rows = base.ctx.repos.plata.timeline.read(until=CORTE)
assert rows
assert rows == kit_rows(base, hasta=CORTE)
def test_the_patient_filter_matches_the_kit(base):
base.correr("catalogos", "cargar")
patients = sorted({row["pac_id"] for row in kit_rows(base)})[:2]
rows = base.ctx.repos.plata.timeline.read(patients=patients, until=CORTE)
assert {row["pac_id"] for row in rows} == set(patients)
assert rows == kit_rows(base, pacientes=patients, hasta=CORTE)
def test_known_until_cuts_at_what_was_loaded(base):
before = datetime.now(timezone.utc) - timedelta(days=1)
base.correr("catalogos", "cargar")
after = datetime.now(timezone.utc) + timedelta(days=1)
timeline = base.ctx.repos.plata.timeline
assert timeline.read(until=CORTE, known_until=before) == []
assert timeline.read(until=CORTE, known_until=after) == kit_rows(base, hasta=CORTE, conocida_hasta=after)
assert timeline.read(until=CORTE, known_until=after) == timeline.read(until=CORTE)