feat: Introduce bot-descarga service for PDF downloads and remote bot control. Add Docker configuration, environment variables, and a GUI for agent management. Enhance README with bot details and installation instructions.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from bot_descarga.models.resultado import RunSummary
|
||||
from bot_descarga.core.download_service import DownloadService
|
||||
|
||||
|
||||
def test_download_service_accepts_should_cancel(monkeypatch):
|
||||
"""Verifica que should_cancel se honra antes de procesar radicados."""
|
||||
calls = {"cancel_checks": 0}
|
||||
|
||||
def fake_read(_self, _path):
|
||||
from bot_descarga.models.radicado import RadicadoRecord
|
||||
return [
|
||||
RadicadoRecord("1", "NIT1"),
|
||||
RadicadoRecord("2", "NIT1"),
|
||||
]
|
||||
|
||||
class FakeBrowser:
|
||||
def start(self, *a, **k):
|
||||
return object(), object()
|
||||
|
||||
def is_alive(self):
|
||||
return True
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def reconnect(self, *a, **k):
|
||||
return object(), object()
|
||||
|
||||
monkeypatch.setattr(
|
||||
"bot_descarga.core.download_service.ExcelReader.read",
|
||||
fake_read,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"bot_descarga.core.download_service.BrowserManager",
|
||||
lambda settings=None: FakeBrowser(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"bot_descarga.core.download_service.ImagingClient",
|
||||
lambda *a, **k: object(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"bot_descarga.core.download_service.JsonlLogger",
|
||||
lambda *a, **k: type("L", (), {"path": "x", "write": lambda *x: None, "close": lambda *x: None})(),
|
||||
)
|
||||
|
||||
def should_cancel():
|
||||
calls["cancel_checks"] += 1
|
||||
return True
|
||||
|
||||
svc = DownloadService(
|
||||
ruta_excel="dummy.xlsx",
|
||||
carpeta_descarga=".",
|
||||
should_cancel=should_cancel,
|
||||
event_callback=lambda e: None,
|
||||
)
|
||||
# Evitar crear carpeta real problemática: FileManager.mkdirs ok
|
||||
summary = svc.run()
|
||||
assert isinstance(summary, RunSummary)
|
||||
assert summary.cancelled is True
|
||||
assert calls["cancel_checks"] >= 1
|
||||
Reference in New Issue
Block a user