grantforge-api / backend /tests /test_export_documents.py
GrantForge Bot
Deploy sha-9a5957fcdef15b7e2623f8b147cda6026475aee0 — source build (no GHCR)
3a3734f
Raw
History Blame Contribute Delete
1.75 kB
import os
import pytest
from bs4 import BeautifulSoup
from utils.export_documents import export_to_docx, export_to_pdf
@pytest.fixture
def sample_markdown():
return """
# Wniosek o Dofinansowanie
## Sekcja 1: Opis
To jest testowy opis z **pogrubionym textem** oraz *kursywą*.
### Wyliczenia
- Punkt 1: **ważny** element
- Punkt 2: zwykły element
### Tabela
| Kolumna 1 | Kolumna 2 |
| --------- | --------- |
| Dane 1 | **Wartość** |
| Dane 2 | 123.45 |
"""
@pytest.fixture
def temp_output_dir(tmp_path):
return str(tmp_path)
def test_export_to_docx(sample_markdown, temp_output_dir):
out_file = os.path.join(temp_output_dir, "test.docx")
# Próba wygenerowania docx
result = export_to_docx(
content=sample_markdown,
output_path=out_file,
project_title="Test Project",
company_name="Test Company",
version="1.0"
)
assert result is True
assert os.path.exists(out_file)
assert os.path.getsize(out_file) > 1000 # sprawdzenie czy plik nie jest pusty
def test_export_to_pdf(sample_markdown, temp_output_dir):
out_file = os.path.join(temp_output_dir, "test.pdf")
# Zabezpieczenie na wypadek braku xhtml2pdf / weasyprint
try:
import xhtml2pdf
has_lib = True
except ImportError:
has_lib = False
if not has_lib:
pytest.skip("Brak xhtml2pdf zainstalowanego. Pomijam test PDF.")
result = export_to_pdf(
content=sample_markdown,
output_path=out_file,
project_title="Test Project PDF",
company_name="Test Company",
version="1.0"
)
assert result is True
assert os.path.exists(out_file)
assert os.path.getsize(out_file) > 1000