Fix tests fallidos
Browse files- tests/test_auditoria.py +3 -41
tests/test_auditoria.py
CHANGED
|
@@ -1,17 +1,14 @@
|
|
| 1 |
"""
|
| 2 |
-
Tests de auditoría: endpoint GET REST,
|
| 3 |
-
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
from types import SimpleNamespace
|
| 8 |
from unittest.mock import MagicMock
|
| 9 |
|
| 10 |
-
import pytest
|
| 11 |
from fastapi.testclient import TestClient
|
| 12 |
-
from starlette.websockets import WebSocketDisconnect
|
| 13 |
|
| 14 |
-
from app.dependencies import create_access_token
|
| 15 |
from app.crud import auditoria as auditoria_crud
|
| 16 |
from tests.factories import make_cama
|
| 17 |
|
|
@@ -142,38 +139,3 @@ def test_crear_cama_ok_aunque_falle_auditoria(client: TestClient, admin_headers,
|
|
| 142 |
assert resp.status_code == 201
|
| 143 |
|
| 144 |
|
| 145 |
-
# ─── WebSocket ───────────────────────────────────────────────────────────────
|
| 146 |
-
|
| 147 |
-
def _token(rol: str = "MEDICO") -> str:
|
| 148 |
-
return create_access_token(sub="1", rol=rol)
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
def test_ws_sin_token_se_rechaza(client: TestClient):
|
| 152 |
-
with pytest.raises(WebSocketDisconnect):
|
| 153 |
-
with client.websocket_connect(f"{PREFIX}/ws") as ws:
|
| 154 |
-
ws.receive_json()
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
def test_ws_envia_snapshot_al_conectar(client: TestClient, monkeypatch):
|
| 158 |
-
monkeypatch.setattr(
|
| 159 |
-
"app.crud.auditoria.get_all",
|
| 160 |
-
lambda *a, **k: ([make_evento()], 1),
|
| 161 |
-
)
|
| 162 |
-
with client.websocket_connect(f"{PREFIX}/ws?token={_token()}&cama_id=101") as ws:
|
| 163 |
-
msg = ws.receive_json()
|
| 164 |
-
assert msg["tipo"] == "snapshot"
|
| 165 |
-
assert msg["total"] == 1
|
| 166 |
-
assert msg["eventos"][0]["evento"] == "CAMA_CAMBIO_ESTADO"
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
# ─── Hub: filtrado por conexión ──────────────────────────────────────────────
|
| 170 |
-
|
| 171 |
-
def test_hub_match_respeta_filtros():
|
| 172 |
-
from app.realtime import _match
|
| 173 |
-
|
| 174 |
-
evento = {"cama_id": 101, "entidad": "CAMA", "paciente_id": 7}
|
| 175 |
-
assert _match(evento, {}) is True
|
| 176 |
-
assert _match(evento, {"cama_id": 101}) is True
|
| 177 |
-
assert _match(evento, {"cama_id": 999}) is False
|
| 178 |
-
assert _match(evento, {"entidad": "CAMA", "paciente_id": 7}) is True
|
| 179 |
-
assert _match(evento, {"paciente_id": 8}) is False
|
|
|
|
| 1 |
"""
|
| 2 |
+
Tests de auditoría: endpoint GET REST, instrumentación de los servicios y
|
| 3 |
+
garantía de que el registro es best-effort (nunca rompe la operación de negocio).
|
| 4 |
+
El tiempo real lo maneja Supabase Realtime directamente; no hay WebSocket en M6.
|
| 5 |
"""
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
from types import SimpleNamespace
|
| 8 |
from unittest.mock import MagicMock
|
| 9 |
|
|
|
|
| 10 |
from fastapi.testclient import TestClient
|
|
|
|
| 11 |
|
|
|
|
| 12 |
from app.crud import auditoria as auditoria_crud
|
| 13 |
from tests.factories import make_cama
|
| 14 |
|
|
|
|
| 139 |
assert resp.status_code == 201
|
| 140 |
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|