from __future__ import annotations import tempfile from pathlib import Path from openpyxl import Workbook from bot_descarga.infrastructure.excel_reader import ExcelReader, limpiar_nombre_carpeta def _make_excel(rows, path: Path) -> Path: wb = Workbook() ws = wb.active for row in rows: ws.append(row) wb.save(path) return path def test_limpiar_nombre_carpeta_caracteres_invalidos(): assert limpiar_nombre_carpeta(r"900/123:456") == "900_123_456" assert limpiar_nombre_carpeta(" ") == "SIN_NIT" assert limpiar_nombre_carpeta("") == "SIN_NIT" def test_excel_reader_lee_radicados_y_nit(): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "datos.xlsx" _make_excel( [ ["Radicado", "NIT"], ["100001", "900111222"], ["100002", "900111222"], ["100003", None], ["", "800"], ], path, ) records = ExcelReader().read(str(path)) assert len(records) == 3 assert records[0].radicado == "100001" assert records[0].nit == "900111222" assert records[2].nit == "SIN_NIT" def test_excel_reader_omite_encabezados_variantes(): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "datos.xlsx" _make_excel( [ ["proceso", "nit"], ["nĂºmero", "nit"], ["555", "1"], ], path, ) records = ExcelReader().read(str(path)) assert len(records) == 1 assert records[0].radicado == "555"