43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
|
|
"""
|
|||
|
|
Integrationstest mit echtem LibreOffice.
|
|||
|
|
|
|||
|
|
Per Default übersprungen — nur aktiv, wenn pytest explizit mit
|
|||
|
|
'-m integration' aufgerufen wird ODER 'soffice' im PATH gefunden wird.
|
|||
|
|
|
|||
|
|
Beispielaufruf im Container:
|
|||
|
|
docker compose exec web pytest -m integration mailmerge/tests/test_preview_integration.py
|
|||
|
|
"""
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
import io
|
|||
|
|
import shutil
|
|||
|
|
from pathlib import Path
|
|||
|
|
|
|||
|
|
import pytest
|
|||
|
|
|
|||
|
|
from mailmerge.services.preview import build_preview
|
|||
|
|
from mailmerge.tests.conftest import CSV_VALID
|
|||
|
|
|
|||
|
|
|
|||
|
|
pytestmark = [
|
|||
|
|
pytest.mark.integration,
|
|||
|
|
pytest.mark.skipif(
|
|||
|
|
shutil.which("soffice") is None,
|
|||
|
|
reason="LibreOffice (soffice) nicht im PATH – Integrationstest übersprungen",
|
|||
|
|
),
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_real_libreoffice_produces_pdf(docx_file_on_disk):
|
|||
|
|
"""End-to-End mit echtem LibreOffice. Erwartet gültige PDF-Bytes."""
|
|||
|
|
csv_buf = io.BytesIO(CSV_VALID.encode("utf-8"))
|
|||
|
|
result = build_preview(docx_file_on_disk, csv_buf)
|
|||
|
|
|
|||
|
|
# PDF-Magic-Bytes
|
|||
|
|
assert result.pdf_bytes.startswith(b"%PDF-"), (
|
|||
|
|
f"Kein PDF zurückbekommen, erste 8 Bytes: {result.pdf_bytes[:8]!r}"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Eine Vorschau sollte mindestens ein paar KB groß sein – sonst stimmt was nicht
|
|||
|
|
assert len(result.pdf_bytes) > 500
|