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,69 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from bot_descarga.config.settings import Settings
|
||||
from bot_descarga.infrastructure.file_manager import FileManager
|
||||
from bot_descarga.infrastructure.pdf_validator import PdfValidator
|
||||
|
||||
|
||||
class AlwaysValid:
|
||||
def validate(self, ruta: str):
|
||||
return True, "OK"
|
||||
|
||||
|
||||
class AlwaysInvalid:
|
||||
def validate(self, ruta: str):
|
||||
return False, "corrupto"
|
||||
|
||||
|
||||
def test_ruta_final_crea_carpeta_nit():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fm = FileManager(tmp, AlwaysValid())
|
||||
ruta = fm.ruta_final("900111", "12345")
|
||||
assert Path(ruta).parent.exists()
|
||||
assert Path(ruta).name == "12345.pdf"
|
||||
assert "900111" in ruta
|
||||
|
||||
|
||||
def test_exists_valid_cuando_no_existe():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fm = FileManager(tmp, AlwaysValid())
|
||||
ok, ruta, motivo = fm.exists_valid("900", "1")
|
||||
assert ok is False
|
||||
assert motivo == "no existe"
|
||||
assert ruta.endswith("1.pdf")
|
||||
|
||||
|
||||
def test_exists_valid_cuando_valido():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fm = FileManager(tmp, AlwaysValid())
|
||||
ruta = fm.ruta_final("900", "1")
|
||||
Path(ruta).write_bytes(b"%PDF-dummy")
|
||||
ok, _, motivo = fm.exists_valid("900", "1")
|
||||
assert ok is True
|
||||
assert motivo == "OK"
|
||||
assert Path(ruta).exists()
|
||||
|
||||
|
||||
def test_exists_valid_elimina_corrupto():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fm = FileManager(tmp, AlwaysInvalid())
|
||||
ruta = fm.ruta_final("900", "1")
|
||||
Path(ruta).write_bytes(b"basura")
|
||||
ok, _, motivo = fm.exists_valid("900", "1")
|
||||
assert ok is False
|
||||
assert motivo == "corrupto"
|
||||
assert not Path(ruta).exists()
|
||||
|
||||
|
||||
def test_move_to_final():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fm = FileManager(tmp, PdfValidator(Settings(peso_minimo_bytes=1)))
|
||||
src = Path(tmp) / "temp.pdf"
|
||||
src.write_bytes(b"%PDF-1.4")
|
||||
dest = fm.ruta_final("NIT1", "R1")
|
||||
fm.move_to_final(str(src), dest)
|
||||
assert Path(dest).exists()
|
||||
assert not src.exists()
|
||||
Reference in New Issue
Block a user