feat: refactor to FastAPI architecture v2.0
Some checks failed
Build & Push Docker / build (push) Has been cancelled
Some checks failed
Build & Push Docker / build (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
100
tests/test_pdf.py
Normal file
100
tests/test_pdf.py
Normal file
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
PDF generation tests.
|
||||
"""
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from datetime import time
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.core.pdf_generator import generate_pdf
|
||||
from app.core.validator import ScenarsError
|
||||
from app.main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_generate_pdf_basic():
|
||||
df = pd.DataFrame({
|
||||
'Datum': [pd.Timestamp('2025-11-13').date()],
|
||||
'Zacatek': [time(9, 0)],
|
||||
'Konec': [time(10, 0)],
|
||||
'Program': ['Test Program'],
|
||||
'Typ': ['WORKSHOP'],
|
||||
'Garant': ['John Doe'],
|
||||
'Poznamka': ['Test note'],
|
||||
})
|
||||
|
||||
descriptions = {'WORKSHOP': 'Workshop Type'}
|
||||
colors = {'WORKSHOP': 'FF0070C0'}
|
||||
|
||||
pdf_bytes = generate_pdf(df, "Test PDF", "PDF Detail", descriptions, colors)
|
||||
|
||||
assert isinstance(pdf_bytes, bytes)
|
||||
assert len(pdf_bytes) > 0
|
||||
assert pdf_bytes[:5] == b'%PDF-'
|
||||
|
||||
|
||||
def test_generate_pdf_multiday():
|
||||
df = pd.DataFrame({
|
||||
'Datum': [pd.Timestamp('2025-11-13').date(), pd.Timestamp('2025-11-14').date()],
|
||||
'Zacatek': [time(9, 0), time(14, 0)],
|
||||
'Konec': [time(10, 0), time(15, 0)],
|
||||
'Program': ['Day 1', 'Day 2'],
|
||||
'Typ': ['KEYNOTE', 'WORKSHOP'],
|
||||
'Garant': ['Alice', 'Bob'],
|
||||
'Poznamka': [None, 'Hands-on'],
|
||||
})
|
||||
|
||||
descriptions = {'KEYNOTE': 'Keynote', 'WORKSHOP': 'Workshop'}
|
||||
colors = {'KEYNOTE': 'FFFF0000', 'WORKSHOP': 'FF0070C0'}
|
||||
|
||||
pdf_bytes = generate_pdf(df, "Multi-day", "Two days", descriptions, colors)
|
||||
|
||||
assert isinstance(pdf_bytes, bytes)
|
||||
assert pdf_bytes[:5] == b'%PDF-'
|
||||
|
||||
|
||||
def test_generate_pdf_empty_data():
|
||||
df = pd.DataFrame(columns=['Datum', 'Zacatek', 'Konec', 'Program', 'Typ', 'Garant', 'Poznamka'])
|
||||
|
||||
with pytest.raises(ScenarsError):
|
||||
generate_pdf(df, "Empty", "Detail", {}, {})
|
||||
|
||||
|
||||
def test_generate_pdf_missing_type():
|
||||
df = pd.DataFrame({
|
||||
'Datum': [pd.Timestamp('2025-11-13').date()],
|
||||
'Zacatek': [time(9, 0)],
|
||||
'Konec': [time(10, 0)],
|
||||
'Program': ['Test'],
|
||||
'Typ': ['UNKNOWN'],
|
||||
'Garant': [None],
|
||||
'Poznamka': [None],
|
||||
})
|
||||
|
||||
with pytest.raises(ScenarsError):
|
||||
generate_pdf(df, "Test", "Detail", {}, {})
|
||||
|
||||
|
||||
def test_generate_pdf_api(client):
|
||||
doc = {
|
||||
"event": {"title": "PDF Test", "detail": "API PDF"},
|
||||
"program_types": [{"code": "WS", "description": "Workshop", "color": "#0070C0"}],
|
||||
"blocks": [{
|
||||
"datum": "2025-11-13",
|
||||
"zacatek": "09:00:00",
|
||||
"konec": "10:00:00",
|
||||
"program": "Opening",
|
||||
"typ": "WS",
|
||||
"garant": "John",
|
||||
"poznamka": "Note"
|
||||
}]
|
||||
}
|
||||
r = client.post("/api/generate-pdf", json=doc)
|
||||
assert r.status_code == 200
|
||||
assert r.headers["content-type"] == "application/pdf"
|
||||
assert r.content[:5] == b'%PDF-'
|
||||
Reference in New Issue
Block a user