Files
OnEverControl/backend/tests/test_hardware_service.py
T

44 lines
1.7 KiB
Python

import pytest
from app.services.hardware_service import HardwareService, formatear_comando_hardware, calcular_checksum
def test_checksum_and_formatting():
assert calcular_checksum("\x0220O5") == "18"
assert formatear_comando_hardware(20, "O5") == "\x0220O518\x03"
assert formatear_comando_hardware(20, "T9") == "\x0220T90F\x03"
def test_encolar_apertura_virtual_module_molinete_club():
"""
Verifica que el Módulo Virtual 100004 (ENTRADA VISITAS):
1. Se resuelva a la placa física 100009 (Address 20).
2. Aplique payload O5 correspondiente a Molinete Club (tipo_acceso 7).
3. Genere la trama de apertura \x0220O518\x03.
4. Genere la trama T9 para impresión de ticket \x0220T90F\x03 cuando tipo_identificacion == 1.
"""
ok, res = HardwareService.encolar_apertura(modulo_id=100004, ticket_id=99999999)
assert ok is True
assert res["modulo_solicitado"] == 100004
assert res["modulo_fisico_target"] == 100009
assert res["address"] == 20
assert res["tipo_acceso"] == 7
assert res["is_pass"] is False
assert res["payload"] == "O5"
assert res["comando_trama"] == "\x0220O518\x03"
assert res["trama_ticket"] == "\x0220T90F\x03"
def test_obtener_tipo_acceso_y_es_acceso_peatonal():
"""
Verifica que:
1. Modulo 100004 sea detectado como Molinete Club (7) -> es_acceso_peatonal True.
2. Modulo inexistente o 0 retorne 0 -> es_acceso_peatonal False.
"""
tipo_acc = HardwareService.obtener_tipo_acceso(100004)
assert tipo_acc == 7
assert HardwareService.es_acceso_peatonal(100004) is True
assert HardwareService.obtener_tipo_acceso(0) == 0
assert HardwareService.es_acceso_peatonal(0) is False