Notebook de las rutas de indicadores de CaCu
Siembra una base temporal, levanta la app con el cliente de pruebas y revisa la lista, una figura por semestre y por mes, y los errores 400 y 404. Pruebas: Core 25 passed; Persistance 31 passed; indicadores_kit 564 passed, 2 skipped; WebApi 55 passed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
"""Apoyo de los notebooks: montar la base de un dominio en una carpeta temporal.
|
||||||
|
|
||||||
|
Hace lo mismo que el fixture `base_del_dominio` de `tests/test_produccion.py`:
|
||||||
|
apunta Persistance a un archivo SQLite, migra con Alembic y llena el
|
||||||
|
staging con los fixtures del kit. Desde ahí, los pasos de
|
||||||
|
`indicadores_kit.pasos` corren por el camino de producción (repositorios
|
||||||
|
de Persistance). No es parte del paquete.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import persistance
|
||||||
|
import persistance.db
|
||||||
|
from alembic import command
|
||||||
|
from alembic.config import Config
|
||||||
|
from persistance.settings import settings
|
||||||
|
|
||||||
|
from indicadores_kit.cacu import fixtures as fixtures_cacu
|
||||||
|
from indicadores_kit.cama import fixtures as fixtures_cama
|
||||||
|
from indicadores_kit.pasos import fabrica_por_defecto
|
||||||
|
from indicadores_kit.registry.parametros import RUTA_PARAMETROS
|
||||||
|
|
||||||
|
FIXTURES = {"cacu": fixtures_cacu, "cama": fixtures_cama}
|
||||||
|
MOTORES = (
|
||||||
|
persistance.db.get_cacu_engine,
|
||||||
|
persistance.db.get_cama_engine,
|
||||||
|
persistance.db.get_tea_engine,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def montar(proyecto: str, carpeta: Path) -> str:
|
||||||
|
"""La base del proyecto en `carpeta`, migrada y con staging sintético. Devuelve su URL.
|
||||||
|
|
||||||
|
Es lo que hacen `<PROYECTO>_DATABASE_URL` y `alembic upgrade head`.
|
||||||
|
El ajuste se cambia en memoria porque Persistance lo lee al importarse.
|
||||||
|
"""
|
||||||
|
url = f"sqlite:///{carpeta / f'{proyecto}.db'}"
|
||||||
|
setattr(settings, f"{proyecto}_database_url", url)
|
||||||
|
for motor in MOTORES:
|
||||||
|
motor.cache_clear()
|
||||||
|
alembic_ini = Path(persistance.__file__).parent / proyecto / "alembic.ini"
|
||||||
|
command.upgrade(Config(str(alembic_ini)), "head")
|
||||||
|
with fabrica_por_defecto(proyecto)() as sesion:
|
||||||
|
FIXTURES[proyecto].insertar(sesion)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def parametros_sin_supresion(carpeta: Path) -> Path:
|
||||||
|
"""Una copia de `parametros.toml` con el umbral de supresión en 1.
|
||||||
|
|
||||||
|
Con 4 o 5 pacientes por periodo, el umbral de 5 ocultaría casi todo.
|
||||||
|
Es lo que hacen las pruebas de producción.
|
||||||
|
"""
|
||||||
|
ruta = carpeta / "parametros.toml"
|
||||||
|
ruta.write_text(
|
||||||
|
RUTA_PARAMETROS.read_text(encoding="utf-8").replace("valor = 5", "valor = 1"),
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
return ruta
|
||||||
@@ -0,0 +1,544 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "f0fbce7e",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"**Qué revisa este notebook.** Las rutas de indicadores de CaCu (tarea WA-2), el análogo de las de TEA: `webapi/indicadores.py` registra en el blueprint `/cacu`\n",
|
||||||
|
"\n",
|
||||||
|
"| Ruta | Qué devuelve |\n",
|
||||||
|
"|---|---|\n",
|
||||||
|
"| `GET /cacu/indicadores` | id, título, contrato, figuras y tipos de periodo que publica cada indicador |\n",
|
||||||
|
"| `GET /cacu/indicadores/<id>/figuras/<figura>?periodos=&tema=` | JSON de Plotly; 404 si el indicador, la figura o el reporte no existen; 400 si el tema o los periodos están mal |\n",
|
||||||
|
"\n",
|
||||||
|
"Por qué: antes solo TEA servía indicadores y su lógica vivía en su blueprint; ahora es un solo código para todos los proyectos. Los periodos se validan contra los `tipos_periodo` que publica la definición (semestre `AAAA-S1`, mes `AAAA-MM`).\n",
|
||||||
|
"\n",
|
||||||
|
"Todo corre en una carpeta temporal, con la app de Flask dentro del proceso (cliente de pruebas, sin servidor); no deja archivos en el repositorio. Cada sección termina en `assert`."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "2335c99f",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2026-10-11T06:28:58.077856Z",
|
||||||
|
"iopub.status.busy": "2026-10-11T06:28:58.076999Z",
|
||||||
|
"iopub.status.idle": "2026-10-11T06:28:58.933116Z",
|
||||||
|
"shell.execute_reply": "2026-10-11T06:28:58.932355Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import tempfile\n",
|
||||||
|
"from datetime import date\n",
|
||||||
|
"from pathlib import Path\n",
|
||||||
|
"\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"\n",
|
||||||
|
"import apoyo\n",
|
||||||
|
"from indicadores_kit.pasos import calcular_periodos, cargar, fabrica_por_defecto, preparar_registro, vistas\n",
|
||||||
|
"from indicadores_kit.registry.measures import leer_measure, ruta_de_measure\n",
|
||||||
|
"\n",
|
||||||
|
"carpeta = Path(tempfile.mkdtemp(prefix=\"cacu_ind_\"))\n",
|
||||||
|
"parametros = apoyo.parametros_sin_supresion(carpeta)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"def sembrar(proyecto):\n",
|
||||||
|
" \"\"\"Base migrada con staging sintético, cargada, con `<proyecto>_eu8` calculado en semestres y meses.\"\"\"\n",
|
||||||
|
" apoyo.montar(proyecto, carpeta)\n",
|
||||||
|
" cargar(proyecto)\n",
|
||||||
|
" vistas(fabrica_por_defecto(proyecto), proyecto)\n",
|
||||||
|
" preparar_registro(proyecto, 2025, 2025, ruta=parametros, tipos=(\"semestre\", \"mes\"))\n",
|
||||||
|
" medida = leer_measure(ruta_de_measure(proyecto, f\"{proyecto}_eu8\"))\n",
|
||||||
|
" return {\n",
|
||||||
|
" tipo: len(calcular_periodos(proyecto, medida, tipo, date(2025, 1, 1), date(2026, 1, 1), permitir_sin_definir=True))\n",
|
||||||
|
" for tipo in (\"semestre\", \"mes\")\n",
|
||||||
|
" }"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "e0e2fd4c",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## 1. Sembrar y calcular\n",
|
||||||
|
"\n",
|
||||||
|
"`apoyo.montar` apunta Persistance a un SQLite temporal, migra con Alembic y llena el staging con los fixtures del kit. Luego los pasos del kit: carga, vistas, `dim_periodo` con semestres y meses, y el cálculo en los dos tipos de periodo."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "31755e66",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2026-10-11T06:28:58.934834Z",
|
||||||
|
"iopub.status.busy": "2026-10-11T06:28:58.934605Z",
|
||||||
|
"iopub.status.idle": "2026-10-11T06:28:59.262772Z",
|
||||||
|
"shell.execute_reply": "2026-10-11T06:28:59.262146Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Context impl SQLiteImpl.\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Will assume non-transactional DDL.\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade -> 79fe432d52a2, create cacu tables\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade 79fe432d52a2 -> cbb31acf322d, add biometria hematica\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade cbb31acf322d -> 9952833a0048, add indicadores_kit tables\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade 9952833a0048 -> b4a35a200913, add dim_fecha and dim_grupo_edad\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade b4a35a200913 -> 04fa57d42fec, add indicador_definicion\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade 04fa57d42fec -> 1b350354d5ed, add measure_report.parametros_sha\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade 1b350354d5ed -> cbd8fed23729, measure_report kit_version replaces sql_sha\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"INFO [alembic.runtime.migration] Running upgrade cbd8fed23729 -> 8e7534131c73, add result tables\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>reportes calculados</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>semestre</th>\n",
|
||||||
|
" <td>2</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>mes</th>\n",
|
||||||
|
" <td>12</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" reportes calculados\n",
|
||||||
|
"semestre 2\n",
|
||||||
|
"mes 12"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"calculados = sembrar(\"cacu\")\n",
|
||||||
|
"assert calculados == {\"semestre\": 2, \"mes\": 12}\n",
|
||||||
|
"pd.Series(calculados, name=\"reportes calculados\").to_frame()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "3742a259",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## 2. Levantar la app"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"id": "dd463639",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2026-10-11T06:28:59.264658Z",
|
||||||
|
"iopub.status.busy": "2026-10-11T06:28:59.264546Z",
|
||||||
|
"iopub.status.idle": "2026-10-11T06:28:59.539493Z",
|
||||||
|
"shell.execute_reply": "2026-10-11T06:28:59.539048Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from webapi import create_app\n",
|
||||||
|
"\n",
|
||||||
|
"app = create_app()\n",
|
||||||
|
"app.config.update(TESTING=True)\n",
|
||||||
|
"cliente = app.test_client()\n",
|
||||||
|
"assert cliente.get(\"/health\").status_code == 200"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "dece2719",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## 3. `GET /cacu/indicadores`\n",
|
||||||
|
"\n",
|
||||||
|
"La lista sale de las definiciones del kit. CaCu no tiene ficha: su figura es un punto por periodo."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "bc5fe03c",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2026-10-11T06:28:59.541734Z",
|
||||||
|
"iopub.status.busy": "2026-10-11T06:28:59.541594Z",
|
||||||
|
"iopub.status.idle": "2026-10-11T06:28:59.549005Z",
|
||||||
|
"shell.execute_reply": "2026-10-11T06:28:59.548360Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>contrato</th>\n",
|
||||||
|
" <th>figuras</th>\n",
|
||||||
|
" <th>id</th>\n",
|
||||||
|
" <th>tipos_periodo</th>\n",
|
||||||
|
" <th>titulo</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>C1</td>\n",
|
||||||
|
" <td>[fig_c1_puntos]</td>\n",
|
||||||
|
" <td>cacu_eu8</td>\n",
|
||||||
|
" <td>[semestre, mes]</td>\n",
|
||||||
|
" <td>Tasa de referencia a repetir citología</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" contrato figuras id tipos_periodo \\\n",
|
||||||
|
"0 C1 [fig_c1_puntos] cacu_eu8 [semestre, mes] \n",
|
||||||
|
"\n",
|
||||||
|
" titulo \n",
|
||||||
|
"0 Tasa de referencia a repetir citología "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"respuesta = cliente.get(\"/cacu/indicadores\")\n",
|
||||||
|
"assert respuesta.status_code == 200\n",
|
||||||
|
"(fila,) = respuesta.get_json()\n",
|
||||||
|
"assert fila[\"id\"] == \"cacu_eu8\"\n",
|
||||||
|
"assert fila[\"contrato\"] == \"C1\" and fila[\"figuras\"] == [\"fig_c1_puntos\"]\n",
|
||||||
|
"assert fila[\"tipos_periodo\"] == [\"semestre\", \"mes\"]\n",
|
||||||
|
"pd.DataFrame([fila])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "b04a81c8",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## 4. Una figura por semestre y una por mes\n",
|
||||||
|
"\n",
|
||||||
|
"Sin `?periodos=` se usan los periodos con reporte del primer tipo que publica la definición (semestre). Con meses, se piden explícitos."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"id": "91e6686f",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2026-10-11T06:28:59.550578Z",
|
||||||
|
"iopub.status.busy": "2026-10-11T06:28:59.550464Z",
|
||||||
|
"iopub.status.idle": "2026-10-11T06:28:59.791898Z",
|
||||||
|
"shell.execute_reply": "2026-10-11T06:28:59.791286Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"(['2025-S1', '2025-S2'], ['2025-01', '2025-02', '2025-03'])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"def eje_x(respuesta):\n",
|
||||||
|
" return sorted({x for trazo in respuesta.get_json()[\"data\"] for x in trazo[\"x\"]})\n",
|
||||||
|
"\n",
|
||||||
|
"base = \"/cacu/indicadores/cacu_eu8/figuras/fig_c1_puntos\"\n",
|
||||||
|
"semestres = cliente.get(base)\n",
|
||||||
|
"assert semestres.status_code == 200 and semestres.mimetype == \"application/json\"\n",
|
||||||
|
"assert eje_x(semestres) == [\"2025-S1\", \"2025-S2\"]\n",
|
||||||
|
"meses = cliente.get(base + \"?periodos=2025-01,2025-02,2025-03&tema=oscuro\")\n",
|
||||||
|
"assert meses.status_code == 200\n",
|
||||||
|
"assert eje_x(meses) == [\"2025-01\", \"2025-02\", \"2025-03\"]\n",
|
||||||
|
"eje_x(semestres), eje_x(meses)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "a0cc37ed",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## 5. Los errores\n",
|
||||||
|
"\n",
|
||||||
|
"400: tema o periodos mal formados, un tipo que el indicador no publica o tipos mezclados. 404: indicador o figura desconocidos, o un periodo sin reporte."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"id": "3293057d",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2026-10-11T06:28:59.793886Z",
|
||||||
|
"iopub.status.busy": "2026-10-11T06:28:59.793756Z",
|
||||||
|
"iopub.status.idle": "2026-10-11T06:28:59.804684Z",
|
||||||
|
"shell.execute_reply": "2026-10-11T06:28:59.804012Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>caso</th>\n",
|
||||||
|
" <th>código</th>\n",
|
||||||
|
" <th>error</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>tema desconocido</td>\n",
|
||||||
|
" <td>400</td>\n",
|
||||||
|
" <td>tema desconocido 'rojo'; use claro u oscuro</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>periodo mal formado</td>\n",
|
||||||
|
" <td>400</td>\n",
|
||||||
|
" <td>Periodos mal formados: '2025-1'; este indicado...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>tipo que no publica</td>\n",
|
||||||
|
" <td>400</td>\n",
|
||||||
|
" <td>Periodos mal formados: '2025-T1'; este indicad...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>tipos mezclados</td>\n",
|
||||||
|
" <td>400</td>\n",
|
||||||
|
" <td>Periodos de tipos distintos: '2025-S1,2025-03'...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>indicador desconocido</td>\n",
|
||||||
|
" <td>404</td>\n",
|
||||||
|
" <td>indicador desconocido</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>5</th>\n",
|
||||||
|
" <td>figura de otro contrato</td>\n",
|
||||||
|
" <td>404</td>\n",
|
||||||
|
" <td>figura 'fig_c2_apiladas' no es del contrato C1</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>6</th>\n",
|
||||||
|
" <td>semestre sin reporte</td>\n",
|
||||||
|
" <td>404</td>\n",
|
||||||
|
" <td>No hay reporte de cacu/CACU_EU8 0.1.0 para 203...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>7</th>\n",
|
||||||
|
" <td>mes sin reporte</td>\n",
|
||||||
|
" <td>404</td>\n",
|
||||||
|
" <td>No hay reporte de cacu/CACU_EU8 0.1.0 para 203...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" caso código \\\n",
|
||||||
|
"0 tema desconocido 400 \n",
|
||||||
|
"1 periodo mal formado 400 \n",
|
||||||
|
"2 tipo que no publica 400 \n",
|
||||||
|
"3 tipos mezclados 400 \n",
|
||||||
|
"4 indicador desconocido 404 \n",
|
||||||
|
"5 figura de otro contrato 404 \n",
|
||||||
|
"6 semestre sin reporte 404 \n",
|
||||||
|
"7 mes sin reporte 404 \n",
|
||||||
|
"\n",
|
||||||
|
" error \n",
|
||||||
|
"0 tema desconocido 'rojo'; use claro u oscuro \n",
|
||||||
|
"1 Periodos mal formados: '2025-1'; este indicado... \n",
|
||||||
|
"2 Periodos mal formados: '2025-T1'; este indicad... \n",
|
||||||
|
"3 Periodos de tipos distintos: '2025-S1,2025-03'... \n",
|
||||||
|
"4 indicador desconocido \n",
|
||||||
|
"5 figura 'fig_c2_apiladas' no es del contrato C1 \n",
|
||||||
|
"6 No hay reporte de cacu/CACU_EU8 0.1.0 para 203... \n",
|
||||||
|
"7 No hay reporte de cacu/CACU_EU8 0.1.0 para 203... "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 6,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"casos = {\n",
|
||||||
|
" \"tema desconocido\": (base + \"?tema=rojo\", 400),\n",
|
||||||
|
" \"periodo mal formado\": (base + \"?periodos=2025-1\", 400),\n",
|
||||||
|
" \"tipo que no publica\": (base + \"?periodos=2025-T1\", 400),\n",
|
||||||
|
" \"tipos mezclados\": (base + \"?periodos=2025-S1,2025-03\", 400),\n",
|
||||||
|
" \"indicador desconocido\": (\"/cacu/indicadores/NO_EXISTE/figuras/fig_c1_puntos\", 404),\n",
|
||||||
|
" \"figura de otro contrato\": (\"/cacu/indicadores/cacu_eu8/figuras/fig_c2_apiladas\", 404),\n",
|
||||||
|
" \"semestre sin reporte\": (base + \"?periodos=2030-S1\", 404),\n",
|
||||||
|
" \"mes sin reporte\": (base + \"?periodos=2030-11\", 404),\n",
|
||||||
|
"}\n",
|
||||||
|
"filas = []\n",
|
||||||
|
"for nombre, (ruta, esperado) in casos.items():\n",
|
||||||
|
" respuesta = cliente.get(ruta)\n",
|
||||||
|
" assert respuesta.status_code == esperado, (nombre, respuesta.status_code)\n",
|
||||||
|
" assert \"error\" in respuesta.get_json()\n",
|
||||||
|
" filas.append({\"caso\": nombre, \"código\": respuesta.status_code, \"error\": respuesta.get_json()[\"error\"]})\n",
|
||||||
|
"pd.DataFrame(filas)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.14.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user