Files
benevoles/backend/tests/test_position_sheets_pdf.py
T
AdamThomasandClaude Sonnet 5 f1d88302a4 Feuilles de poste : ajouter le référent en en-tête
Nom + téléphone du référent du poste (Position.lead_account_id), juste
sous le sous-titre (jour/lieu) — « Référent : à désigner » si aucun.
Même source que le référent affiché à l'écran bénévole
(volunteers.py:get_volunteer_planning).

Vérifié : pytest (287 passés, dont les nouveaux tests avec/sans
référent), ruff, alembic check — tous verts (pas de changement
frontend, la feuille reste un simple téléchargement de PDF).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 18:21:26 +02:00

91 lines
2.7 KiB
Python

"""Génération des feuilles de poste (module pur, sans base)."""
import datetime as dt
from app.sheets.pdf import (
PositionDaySheet,
SheetShift,
SheetVolunteer,
generate_position_sheets_pdf,
)
def _sheet(volunteers=(), min_staff=1, ideal_staff=2) -> PositionDaySheet:
return PositionDaySheet(
position_name="Bar central",
position_location="Chapiteau",
date=dt.date(2026, 7, 10),
shifts=(
SheetShift(
starts_at=dt.datetime(2026, 7, 10, 19, 0),
ends_at=dt.datetime(2026, 7, 10, 22, 0),
min_staff=min_staff,
ideal_staff=ideal_staff,
volunteers=volunteers,
),
),
)
def test_shift_is_understaffed_when_below_min_staff():
fully_staffed = _sheet(
volunteers=(SheetVolunteer(name="Alex Martin", phone="0600000000"),),
min_staff=1,
)
assert fully_staffed.shifts[0].understaffed is False
understaffed = _sheet(volunteers=(), min_staff=1)
assert understaffed.shifts[0].understaffed is True
def test_generates_a_valid_pdf_with_volunteers():
sheet = _sheet(
volunteers=(
SheetVolunteer(name="Alex Martin", phone="0600000000"),
SheetVolunteer(name="Sam Nuit", phone=None),
)
)
pdf = generate_position_sheets_pdf([sheet])
assert pdf.startswith(b"%PDF")
assert pdf.rstrip().endswith(b"%%EOF")
def test_generates_a_valid_pdf_with_no_volunteers_assigned():
pdf = generate_position_sheets_pdf([_sheet(volunteers=())])
assert pdf.startswith(b"%PDF")
def test_generates_a_valid_pdf_with_no_shifts_that_day():
sheet = PositionDaySheet(
position_name="Bar central", position_location=None,
date=dt.date(2026, 7, 10), shifts=(),
)
pdf = generate_position_sheets_pdf([sheet])
assert pdf.startswith(b"%PDF")
def test_multiple_sheets_produce_a_larger_pdf():
one = generate_position_sheets_pdf([_sheet()])
two = generate_position_sheets_pdf([_sheet(), _sheet()])
assert len(two) > len(one)
def test_generates_a_valid_pdf_with_a_referent():
sheet = PositionDaySheet(
position_name="Bar central", position_location="Chapiteau",
date=dt.date(2026, 7, 10), shifts=(),
referent_name="Sam Nuit", referent_phone="0600000000",
)
pdf = generate_position_sheets_pdf([sheet])
assert pdf.startswith(b"%PDF")
def test_generates_a_valid_pdf_without_a_referent():
sheet = PositionDaySheet(
position_name="Bar central", position_location="Chapiteau",
date=dt.date(2026, 7, 10), shifts=(),
)
assert sheet.referent_name is None
pdf = generate_position_sheets_pdf([sheet])
assert pdf.startswith(b"%PDF")