Files
WebApi/tests/test_seguimiento.py
T
Roberto Treviño Cervantes f65d5f3f4d preliminary release
2026-10-29 12:12:28 -06:00

68 lines
2.6 KiB
Python

"""La lista de seguimiento (T-24d): `GET /cacu/seguimiento`, solo en DEV y 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: cuándo existe, la forma y los códigos de error.
"""
import pytest
from conftest import cliente_de
LLAVES = {"simulado", "corte", "ventana", "filtros", "estatus_disponibles", "reglas", "paginacion", "items"}
LLAVES_DEL_ITEM = {"id_seudonimo", "grupo_edad", "estatus", "ultima_citologia", "ultimo_vph",
"dias_toma_diagnostico", "prioridad"} # fmt: skip
@pytest.fixture(scope="module")
def client(tmp_path_factory):
with pytest.MonkeyPatch.context() as mp:
mp.setenv("DEV_REVISION", "prueba")
yield from cliente_de("cacu", tmp_path_factory)
@pytest.fixture(scope="module")
def fuera_de_dev(tmp_path_factory):
with pytest.MonkeyPatch.context() as mp:
mp.delenv("DEV_REVISION", raising=False)
yield from cliente_de("cacu", tmp_path_factory)
def test_en_dev_la_lista_tiene_la_forma_del_contrato_y_es_simulada(client):
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"])
assert "pac_id" 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_fuera_de_dev_la_ruta_no_existe(fuera_de_dev):
assert fuera_de_dev.get("/cacu/seguimiento").status_code == 404