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,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from bot_descarga.config.settings import Settings
|
||||
from bot_descarga.infrastructure.pdf_validator import PdfValidator
|
||||
|
||||
|
||||
def test_validate_rechaza_archivo_pequeno():
|
||||
settings = Settings(peso_minimo_bytes=10_000)
|
||||
validator = PdfValidator(settings)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "tiny.pdf"
|
||||
path.write_bytes(b"%PDF-1.4\n%%EOF\n")
|
||||
ok, motivo = validator.validate(str(path))
|
||||
|
||||
assert ok is False
|
||||
assert "Peso insuficiente" in motivo
|
||||
|
||||
|
||||
def test_validate_rechaza_sin_firma_pdf():
|
||||
settings = Settings(peso_minimo_bytes=10)
|
||||
validator = PdfValidator(settings)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "fake.pdf"
|
||||
path.write_bytes(b"NOTA PDF" + b"x" * 100)
|
||||
ok, motivo = validator.validate(str(path))
|
||||
|
||||
assert ok is False
|
||||
assert "firma" in motivo.lower()
|
||||
|
||||
|
||||
def test_validate_acepta_pdf_minimo_valido():
|
||||
"""PDF mínimo con firma, EOF y estructura pikepdf-compatible."""
|
||||
import pikepdf
|
||||
|
||||
settings = Settings(peso_minimo_bytes=50)
|
||||
validator = PdfValidator(settings)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "ok.pdf"
|
||||
pdf = pikepdf.Pdf.new()
|
||||
# Varias páginas para superar el peso mínimo sin corromper el archivo
|
||||
for _ in range(5):
|
||||
pdf.add_blank_page(page_size=(612, 792))
|
||||
pdf.save(path)
|
||||
|
||||
ok, motivo = validator.validate(str(path))
|
||||
|
||||
assert ok is True, motivo
|
||||
assert motivo == "OK"
|
||||
Reference in New Issue
Block a user