Le paramétrage des créneaux se fait dans « Règles & édition » : la coordination
définit des créneaux types (DayPart). À la création d'un poste, un créneau à
besoin 0/0 est généré pour chaque jour de l'édition et chaque créneau type ;
les coordinateurs ajustent ensuite min/idéal.
Back-end :
- DayPart CRUD (GET/POST/PATCH/DELETE /editions/{id}/day-parts). Code figé
après création (slugifié depuis le libellé si absent), unique par édition.
- Shift.day_part_id (nullable, SET NULL) + migration 0004.
- create_position génère les créneaux ; POST .../positions/{pid}/generate-shifts
recrée les manquants (idempotent, ne touche pas aux besoins déjà réglés).
- 13 tests (day-parts, génération, extension d'édition, ajout de type).
Front-end :
- api/hooks/mock : dayParts CRUD + positions.generateShifts.
- ConfigRules : panneau « Créneaux types » (libellé + horaires éditables,
ajout, suppression).
- ConfigGrid : bouton « Générer les créneaux » sur l'en-tête du poste.
- GrillePage : case « à définir » (gris, glyphe ·) quand min=idéal=0, avec
entrée de légende.
155 tests back OK ; typecheck + lint + build + smoke front OK.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
"""Génération des créneaux d'un poste à partir des créneaux types."""
|
|
|
|
|
|
def _positions_url(edition):
|
|
return f"/editions/{edition.id}/positions"
|
|
|
|
|
|
def _create_position(client, edition, name="Bar"):
|
|
return client.post(
|
|
_positions_url(edition), json={"name": name, "category": "BAR"}
|
|
).json()
|
|
|
|
|
|
def test_creating_a_position_generates_one_shift_per_day_and_type(client, edition):
|
|
position = _create_position(client, edition)
|
|
shifts = client.get(
|
|
f"/editions/{edition.id}/shifts", params={"position_id": position["id"]}
|
|
).json()
|
|
# 4 jours (2026-07-09..12) x 3 créneaux types.
|
|
assert len(shifts) == 12
|
|
assert all(s["min_staff"] == 0 and s["ideal_staff"] == 0 for s in shifts)
|
|
assert all(s["day_part_id"] is not None for s in shifts)
|
|
|
|
|
|
def test_generate_is_idempotent(client, edition):
|
|
position = _create_position(client, edition)
|
|
resp = client.post(
|
|
f"{_positions_url(edition)}/{position['id']}/generate-shifts"
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["created"] == 0
|
|
|
|
|
|
def test_extending_the_edition_then_generating_adds_the_new_days(client, edition):
|
|
position = _create_position(client, edition)
|
|
client.patch(f"/editions/{edition.id}", json={"end_date": "2026-07-14"})
|
|
|
|
resp = client.post(
|
|
f"{_positions_url(edition)}/{position['id']}/generate-shifts"
|
|
)
|
|
# 2 jours de plus x 3 créneaux types.
|
|
assert resp.json()["created"] == 6
|
|
shifts = client.get(
|
|
f"/editions/{edition.id}/shifts", params={"position_id": position["id"]}
|
|
).json()
|
|
assert len(shifts) == 18
|
|
|
|
|
|
def test_adding_a_day_part_then_generating_adds_it_everywhere(client, edition):
|
|
position = _create_position(client, edition)
|
|
client.post(
|
|
f"/editions/{edition.id}/day-parts",
|
|
json={"label": "Nuit", "start_time": "02:00", "end_time": "05:00"},
|
|
)
|
|
resp = client.post(
|
|
f"{_positions_url(edition)}/{position['id']}/generate-shifts"
|
|
)
|
|
assert resp.json()["created"] == 4 # 1 par jour
|
|
|
|
|
|
def test_generation_does_not_touch_staffing_already_set(client, edition):
|
|
position = _create_position(client, edition)
|
|
shift = client.get(
|
|
f"/editions/{edition.id}/shifts", params={"position_id": position["id"]}
|
|
).json()[0]
|
|
client.patch(
|
|
f"/editions/{edition.id}/shifts/{shift['id']}",
|
|
json={"min_staff": 3, "ideal_staff": 5},
|
|
)
|
|
client.post(f"{_positions_url(edition)}/{position['id']}/generate-shifts")
|
|
again = client.get(f"/editions/{edition.id}/shifts/{shift['id']}").json()
|
|
assert again["min_staff"] == 3 and again["ideal_staff"] == 5
|