38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
from datetime import date
|
|
|
|
from sqlalchemy import Column, Date, Integer, MetaData, String, Table, create_engine, select
|
|
from sqlmodel import Session
|
|
|
|
from webapi.follow_up import listing
|
|
|
|
|
|
def test_study_window_filters_on_collection_or_report_date_without_exposing_future_results(monkeypatch):
|
|
metadata = MetaData()
|
|
studies = Table(
|
|
"study_fixture", metadata,
|
|
Column("pac_id", Integer), Column("fecha_toma", Date), Column("fecha_reporte", Date),
|
|
Column("calidad_muestra", String), Column("resultado", String), Column("vph", String),
|
|
Column("genotipo_16_18", Integer),
|
|
)
|
|
engine = create_engine("sqlite://")
|
|
metadata.create_all(engine)
|
|
monkeypatch.setattr(listing, "citologias", lambda: select(studies).subquery())
|
|
beginning, cutoff = date(2026, 1, 1), date(2026, 1, 31)
|
|
|
|
with Session(engine) as session:
|
|
session.execute(studies.insert(), [
|
|
{"pac_id": 1, "fecha_toma": beginning, "fecha_reporte": cutoff, "resultado": "NORMAL"},
|
|
{"pac_id": 2, "fecha_toma": date(2025, 12, 28), "fecha_reporte": cutoff, "resultado": "LIEBG"},
|
|
{"pac_id": 3, "fecha_toma": cutoff, "fecha_reporte": date(2026, 2, 3), "resultado": "NORMAL"},
|
|
{"pac_id": 4, "fecha_toma": cutoff, "fecha_reporte": None, "resultado": None},
|
|
])
|
|
by_collection = {row["pac_id"]: row for row in listing._estudios(session, cutoff, beginning, "toma")}
|
|
by_report = {row["pac_id"]: row for row in listing._estudios(session, cutoff, beginning, "reporte")}
|
|
|
|
assert set(by_collection) == {1, 3, 4}
|
|
assert by_collection[1]["resultado"] == "NORMAL"
|
|
assert by_collection[3]["resultado"] is None and by_collection[4]["resultado"] is None
|
|
assert set(by_report) == {1, 2}
|
|
assert by_report[2]["resultado"] == "LIEBG"
|
|
engine.dispose()
|