feat(access): paridad funcional de verificacion peaton vs conductor y pulsos a barrera/molinete segun desktop pct_view
This commit is contained in:
@@ -365,3 +365,123 @@ async def test_validations_and_policies():
|
||||
assert "art" in res_art_vencida.json()["detail"].lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_verificaciones_peaton_vs_conductor_hardware_pulse(monkeypatch):
|
||||
"""
|
||||
Verifica la regla de negocio de escritorio (pct_view.py:2861-2868 y 3088-3093):
|
||||
1. Si es Peatón y el módulo es Barrera Vehicular (tipo_acceso=3 o 5):
|
||||
NO se envía pulso de apertura (barrier_opened == False).
|
||||
2. Si es Peatón y el módulo es Molinete o Puerta (tipo_acceso in (1, 2, 7)):
|
||||
SÍ se envía pulso de apertura (barrier_opened == True).
|
||||
3. Si es Conductor:
|
||||
SÍ se envía pulso de apertura independientemente del tipo de acceso (barrier_opened == True).
|
||||
"""
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
login_res = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
json={"username": "guardia", "password": "guardia"},
|
||||
)
|
||||
token = login_res.cookies.get("access_token")
|
||||
|
||||
from app.services.hardware_service import HardwareService
|
||||
|
||||
# Caso 1: Peatón en Molinete Club (100004 -> tipo_acceso=7)
|
||||
res_peaton_molinete = await client.post(
|
||||
"/api/v1/access/entry",
|
||||
json={
|
||||
"modulo_ingreso_id": 100004,
|
||||
"documento": "88771122",
|
||||
"nombre": "PEATON MOLINETE",
|
||||
"lote_codigo": "100",
|
||||
"tipo_ingreso": "PEATON",
|
||||
"abrir_barrera": True,
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
assert res_peaton_molinete.status_code == 200
|
||||
data_molinete = res_peaton_molinete.json()
|
||||
assert data_molinete["barrier_opened"] is True
|
||||
assert "molinete" in data_molinete["message"].lower() or "habilitado" in data_molinete["message"].lower()
|
||||
|
||||
# Egresar para no dejar ticket bloqueante
|
||||
await client.post(
|
||||
"/api/v1/access/exit",
|
||||
json={
|
||||
"ticket_id": data_molinete["ticket_id"],
|
||||
"modulo_salida_id": 100005,
|
||||
"tipo_salida": "PEATON",
|
||||
"abrir_barrera": True,
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
|
||||
# Caso 2: Peatón en Barrera Vehicular (simulamos módulo tipo_acceso = 3: Barrera Estado)
|
||||
monkeypatch.setattr(HardwareService, "obtener_tipo_acceso", lambda mod_id: 3)
|
||||
res_peaton_barrera = await client.post(
|
||||
"/api/v1/access/entry",
|
||||
json={
|
||||
"modulo_ingreso_id": 100004,
|
||||
"documento": "88771133",
|
||||
"nombre": "PEATON BARRERA",
|
||||
"lote_codigo": "100",
|
||||
"tipo_ingreso": "PEATON",
|
||||
"abrir_barrera": True,
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
assert res_peaton_barrera.status_code == 200
|
||||
data_barrera = res_peaton_barrera.json()
|
||||
# Regla clave: NO DEBE ABRIR LA BARRERA VEHICULAR A UN PEATÓN
|
||||
assert data_barrera["barrier_opened"] is False
|
||||
assert "no accionada" in data_barrera["message"].lower()
|
||||
|
||||
# Caso 3: Salida Peatón en Barrera Vehicular -> Tampoco acciona barrera
|
||||
exit_res_barrera = await client.post(
|
||||
"/api/v1/access/exit",
|
||||
json={
|
||||
"ticket_id": data_barrera["ticket_id"],
|
||||
"modulo_salida_id": 100005,
|
||||
"tipo_salida": "PEATON",
|
||||
"abrir_barrera": True,
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
assert exit_res_barrera.status_code == 200
|
||||
assert exit_res_barrera.json()["barrier_opened"] is False
|
||||
|
||||
# Caso 4: Conductor en Barrera Vehicular -> SÍ acciona barrera
|
||||
res_conductor = await client.post(
|
||||
"/api/v1/access/entry",
|
||||
json={
|
||||
"modulo_ingreso_id": 100004,
|
||||
"documento": "88771144",
|
||||
"nombre": "CONDUCTOR BARRERA",
|
||||
"lote_codigo": "100",
|
||||
"tipo_ingreso": "CONDUCTOR",
|
||||
"patente": "ABC789",
|
||||
"abrir_barrera": True,
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
assert res_conductor.status_code == 200
|
||||
data_cond = res_conductor.json()
|
||||
assert data_cond["barrier_opened"] is True
|
||||
|
||||
# Salida Conductor -> SÍ acciona barrera
|
||||
exit_cond = await client.post(
|
||||
"/api/v1/access/exit",
|
||||
json={
|
||||
"ticket_id": data_cond["ticket_id"],
|
||||
"modulo_salida_id": 100005,
|
||||
"patente_salida": "ABC789",
|
||||
"tipo_salida": "CONDUCTOR",
|
||||
"abrir_barrera": True,
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
assert exit_cond.status_code == 200
|
||||
assert exit_cond.json()["barrier_opened"] is True
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user