Lignes trop longues détectées par ruff (badges.py, tests) ; ajout de /badges au smoke test frontend (rendu SSR de chaque écran protégé). Vérifié dans ce commit : pytest (248 passés), ruff check, alembic check, tsc --noEmit, eslint, vite build, smoke — tous verts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
102 lines
3.3 KiB
Python
102 lines
3.3 KiB
Python
"""Texte résolu des champs du badge — fonctions pures (pas de base)."""
|
||
|
||
import datetime as dt
|
||
import uuid
|
||
|
||
from app.api.badges import _field_text, _position_line
|
||
from app.models import (
|
||
BadgeField,
|
||
BadgeFieldType,
|
||
Position,
|
||
PositionCategory,
|
||
Shift,
|
||
Volunteer,
|
||
)
|
||
|
||
|
||
def _volunteer(**kw) -> Volunteer:
|
||
return Volunteer(id=uuid.uuid4(), edition_id=uuid.uuid4(), **kw)
|
||
|
||
|
||
def _position(**kw) -> Position:
|
||
return Position(id=uuid.uuid4(), edition_id=uuid.uuid4(), category=PositionCategory.BAR, **kw)
|
||
|
||
|
||
def _shift(start: dt.datetime, end: dt.datetime) -> Shift:
|
||
return Shift(
|
||
id=uuid.uuid4(), edition_id=uuid.uuid4(), position_id=uuid.uuid4(),
|
||
starts_at=start, ends_at=end,
|
||
)
|
||
|
||
|
||
def test_position_line_shows_the_schedule():
|
||
volunteer = _volunteer(first_name="Alex", last_name="Martin")
|
||
position = _position(name="Bar central")
|
||
shift = _shift(dt.datetime(2026, 7, 9, 19, 0), dt.datetime(2026, 7, 9, 22, 0))
|
||
|
||
line = _position_line(position, shift, referent=None, volunteer_id=volunteer.id)
|
||
|
||
assert line == "Bar central 19:00–22:00"
|
||
|
||
|
||
def test_position_line_shows_the_referent_when_there_is_one():
|
||
volunteer = _volunteer(first_name="Alex", last_name="Martin")
|
||
position = _position(name="Bar central")
|
||
shift = _shift(dt.datetime(2026, 7, 9, 19, 0), dt.datetime(2026, 7, 9, 22, 0))
|
||
referent = _volunteer(first_name="Sam", last_name="Nuit")
|
||
|
||
line = _position_line(position, shift, referent=referent, volunteer_id=volunteer.id)
|
||
|
||
assert line == "Bar central 19:00–22:00 (Référent : Sam Nuit)"
|
||
|
||
|
||
def test_position_line_hides_the_referent_when_it_is_the_badged_volunteer():
|
||
# Pas besoin de se dire à soi-même qu'on est referent de son propre poste.
|
||
volunteer = _volunteer(first_name="Sam", last_name="Nuit")
|
||
|
||
line = _position_line(
|
||
_position(name="Bar central"),
|
||
_shift(dt.datetime(2026, 7, 9, 19, 0), dt.datetime(2026, 7, 9, 22, 0)),
|
||
referent=volunteer,
|
||
volunteer_id=volunteer.id,
|
||
)
|
||
|
||
assert "Référent" not in line
|
||
|
||
|
||
def test_field_text_positions_lists_one_line_per_shift_in_chronological_order():
|
||
volunteer = _volunteer(first_name="Alex", last_name="Martin")
|
||
field = BadgeField(
|
||
edition_id=uuid.uuid4(), field_type=BadgeFieldType.POSITIONS,
|
||
x_mm=0, y_mm=0, width_mm=10, height_mm=10, font_size=9,
|
||
)
|
||
morning = (
|
||
_position(name="Accueil"),
|
||
_shift(dt.datetime(2026, 7, 9, 9, 0), dt.datetime(2026, 7, 9, 13, 0)),
|
||
None,
|
||
)
|
||
evening = (
|
||
_position(name="Bar central"),
|
||
_shift(dt.datetime(2026, 7, 9, 19, 0), dt.datetime(2026, 7, 9, 22, 0)),
|
||
None,
|
||
)
|
||
|
||
text = _field_text(
|
||
field, volunteer,
|
||
assignments_by_volunteer={volunteer.id: [morning, evening]},
|
||
lead_volunteer_ids=set(),
|
||
)
|
||
|
||
assert text == "Accueil 09:00–13:00\nBar central 19:00–22:00"
|
||
|
||
|
||
def test_field_text_role_is_referent_only_for_lead_accounts():
|
||
volunteer = _volunteer(first_name="Sam", last_name="Nuit")
|
||
field = BadgeField(
|
||
edition_id=uuid.uuid4(), field_type=BadgeFieldType.ROLE,
|
||
x_mm=0, y_mm=0, width_mm=10, height_mm=10, font_size=9,
|
||
)
|
||
|
||
assert _field_text(field, volunteer, {}, lead_volunteer_ids=set()) == "Bénévole"
|
||
assert _field_text(field, volunteer, {}, lead_volunteer_ids={volunteer.id}) == "Référent"
|