7640486852
A biopsy reported with a grade of `cacu.seguimiento.caso.grados` (CARCINOMA, provisional) by the reference makes the patient a case: the status wins over every other, and what is followed for her is survival. Only the follow-up list reads this rule; the measures' stratum in dbt is unchanged.
96 lines
4.6 KiB
Python
96 lines
4.6 KiB
Python
"""La lista de seguimiento (T-24d): `GET /cacu/seguimiento`, siempre simulada.
|
|
|
|
Sobre la base de demostración del kit (`conftest.cliente_de`). La lista en sí se prueba en el kit
|
|
(`tests/test_lista_seguimiento.py`); aquí, la ruta: que existe sin `DEV_REVISION`, la forma y los códigos
|
|
de error. Fixtures: `client`, la app sin `DEV_REVISION` sobre la base de demostración de CaCu.
|
|
"""
|
|
|
|
import pytest
|
|
from conftest import cliente_de
|
|
|
|
LLAVES = {"simulado", "corte", "ventana", "filtros", "estatus_disponibles", "reglas", "paginacion", "items"}
|
|
LLAVES_DEL_ITEM = {"pac_id", "id_seudonimo", "grupo_edad", "estatus", "ultima_citologia", "ultimo_vph",
|
|
"dias_toma_diagnostico", "prioridad"} # fmt: skip
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def client(tmp_path_factory):
|
|
"""La app sobre la base de demostración de CaCu, sin `DEV_REVISION` en el entorno."""
|
|
with pytest.MonkeyPatch.context() as mp:
|
|
mp.delenv("DEV_REVISION", raising=False)
|
|
yield from cliente_de("cacu", tmp_path_factory)
|
|
|
|
|
|
def test_la_lista_tiene_la_forma_del_contrato_y_es_simulada(client):
|
|
"""Fija: sin `DEV_REVISION` la ruta existe, con la forma del contrato y `simulado: true`. Falla si la ruta
|
|
vuelve a depender de una variable de entorno o cambia un campo."""
|
|
response = client.get("/cacu/seguimiento?corte=2025-12-31")
|
|
|
|
assert response.status_code == 200 and response.mimetype == "application/json"
|
|
cuerpo = response.get_json()
|
|
assert set(cuerpo) == LLAVES and cuerpo["simulado"] is True
|
|
assert cuerpo["items"] and all(set(i) == LLAVES_DEL_ITEM for i in cuerpo["items"])
|
|
assert all(i["prioridad"] is None for i in cuerpo["items"])
|
|
# The patient key is the platform's `pac_id`, the one the risk route takes; the hospital's id never leaves.
|
|
assert all(i["pac_id"].isdigit() and i["id_seudonimo"] == i["pac_id"] for i in cuerpo["items"])
|
|
assert "pac_id_hospital" not in response.get_data(as_text=True)
|
|
|
|
|
|
def test_el_pedido_se_respeta(client):
|
|
cuerpo = client.get("/cacu/seguimiento?corte=2025-12-31&meses=6&page=1&page_size=2&estatus=PRE_COLPOSCOPIA").get_json()
|
|
|
|
assert cuerpo["ventana"]["meses"] == 6 and cuerpo["paginacion"]["page_size"] == 2
|
|
assert len(cuerpo["items"]) <= 2 and all(i["estatus"]["codigo"] == "PRE_COLPOSCOPIA" for i in cuerpo["items"])
|
|
assert cuerpo["filtros"] == {"estatus": "PRE_COLPOSCOPIA"}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"query",
|
|
["?corte=2025-13", "?corte=ayer", "?meses=2", "?meses=tres", "?estatus=OTRO", "?page=0", "?page_size=500"],
|
|
)
|
|
def test_un_pedido_mal_escrito_o_fuera_de_rango_da_400(client, query):
|
|
response = client.get(f"/cacu/seguimiento{query}")
|
|
|
|
assert response.status_code == 400
|
|
assert "error" in response.get_json()
|
|
|
|
|
|
def test_una_pagina_de_mas_da_404(client):
|
|
response = client.get("/cacu/seguimiento?corte=2025-12-31&page=9999")
|
|
|
|
assert response.status_code == 404
|
|
assert "error" in response.get_json()
|
|
|
|
|
|
def test_in_dev_esta_obsoleta():
|
|
"""Fija: `in_dev()` avisa que está obsoleta. Falla si alguien vuelve a usarla como compuerta sin el aviso."""
|
|
from webapi.follow_up.routes import in_dev
|
|
|
|
with pytest.warns(DeprecationWarning):
|
|
in_dev()
|
|
|
|
|
|
def test_una_biopsia_de_un_grado_de_caso_hace_caso_a_la_paciente(client, monkeypatch):
|
|
"""Fija: quien tiene una biopsia reportada con un grado de `cacu.seguimiento.caso.grados` al corte es CASO, gane lo
|
|
que gane lo demás, y nadie sin una lo es; el filtro `estatus=CASO` las da. La base de demostración no tiene
|
|
carcinomas, así que la regla se toma aquí como CIN2. Falla si la precedencia deja de poner CASO primero o el
|
|
estatus deja de leer el grado de la biopsia de su regla."""
|
|
from sqlalchemy import select
|
|
|
|
from persistance.db import get_cacu_session
|
|
from webapi.follow_up import listing
|
|
from webapi.follow_up.silver import biopsias
|
|
|
|
original = listing.valor_de
|
|
monkeypatch.setattr(listing, "valor_de", lambda sesion, clave, **kw:
|
|
["CIN2"] if clave == "cacu.seguimiento.caso.grados" else original(sesion, clave, **kw))
|
|
b = biopsias()
|
|
with get_cacu_session() as session:
|
|
con_cin2 = {r.pac_id for r in session.execute(select(b.c.pac_id).where(b.c.grado == "CIN2"))}
|
|
filas = client.get("/cacu/seguimiento?corte=2025-12-31&meses=12&page_size=200").get_json()["items"]
|
|
casos = {int(i["pac_id"]) for i in filas if i["estatus"]["codigo"] == "CASO"}
|
|
|
|
assert casos and casos == con_cin2 & {int(i["pac_id"]) for i in filas}
|
|
solo = client.get("/cacu/seguimiento?corte=2025-12-31&meses=12&page_size=200&estatus=CASO").get_json()["items"]
|
|
assert {int(i["pac_id"]) for i in solo} == casos
|