Compétences supprimées de bout en bout :
- tables `skill`, `volunteer_skill`, `shift_required_skill` ;
- `Volunteer.skill_codes`, `Shift.required_skill_codes`, colonne `skills`
de l'import, règle de validation `MISSING_REQUIRED_SKILL`, jeu de démo.
Disponibilités repensées : `Availability` passe de (`day_part_id`,
`status` tri-état) à une **fenêtre horaire libre** (`date`, `start_time`,
`end_time` ; `end <= start` ⇒ passe minuit), plusieurs par jour.
- Nouveaux endpoints `GET`/`PUT /editions/{id}/volunteers/{vid}/availability`
(PUT = remplacement complet, COORDINATION) et
`GET /editions/{id}/availability` (toute l'édition, pour la grille).
- `OUTSIDE_AVAILABILITY` (toujours WARNING) : compare le créneau à l'union
des fenêtres du bénévole ce jour-là ; renvoie `date` + `uncovered_minutes`.
`DayPart` ne sert plus qu'à la borne de « journée » du cumul 8 h.
- L'import ne gère plus les disponibilités (fenêtres saisies dans l'app) :
`values.py` supprimé, mapping réduit à nom/email/téléphone/commentaire.
Migration 0007 (recrée `availability`). `AvailabilityStatus` supprimé.
158 tests, `alembic check` et `ruff` au vert. Front à suivre.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
178 lines
5.4 KiB
Python
178 lines
5.4 KiB
Python
import datetime as dt
|
|
import uuid
|
|
|
|
from sqlmodel import select
|
|
|
|
from app.models import Assignment, Availability, Volunteer
|
|
from tests.factories import (
|
|
dt_at,
|
|
make_artist,
|
|
make_availability,
|
|
make_position,
|
|
make_shift,
|
|
make_volunteer,
|
|
)
|
|
|
|
|
|
def _url(edition, suffix=""):
|
|
return f"/editions/{edition.id}/volunteers{suffix}"
|
|
|
|
|
|
def test_create_volunteer(client, edition):
|
|
resp = client.post(
|
|
_url(edition),
|
|
json={
|
|
"first_name": "Alex",
|
|
"last_name": "Martin",
|
|
"email": "alex@ex.fr",
|
|
},
|
|
)
|
|
assert resp.status_code == 201
|
|
body = resp.json()
|
|
assert body["edition_id"] == str(edition.id)
|
|
assert body["artist_ids"] == []
|
|
assert body["wished_position_ids"] == []
|
|
|
|
|
|
def test_create_duplicate_email_conflicts(client, edition):
|
|
payload = {"first_name": "A", "last_name": "A", "email": "dup@ex.fr"}
|
|
assert client.post(_url(edition), json=payload).status_code == 201
|
|
resp = client.post(_url(edition), json={**payload, "first_name": "B"})
|
|
assert resp.status_code == 409
|
|
assert resp.json()["detail"]["code"] == "volunteer.duplicate_email"
|
|
|
|
|
|
def test_volunteers_without_email_are_allowed(client, edition):
|
|
for name in ("Un", "Deux"):
|
|
r = client.post(
|
|
_url(edition), json={"first_name": name, "last_name": "SansMail"}
|
|
)
|
|
assert r.status_code == 201
|
|
|
|
|
|
def test_list_is_ordered_by_name(client, edition, session):
|
|
make_volunteer(session, edition, first_name="Bob", last_name="Zoe")
|
|
make_volunteer(session, edition, first_name="Ana", last_name="Ada")
|
|
names = [v["last_name"] for v in client.get(_url(edition)).json()]
|
|
assert names == ["Ada", "Zoe"]
|
|
|
|
|
|
def test_get_unknown_id_is_404(client, edition):
|
|
assert client.get(_url(edition, f"/{uuid.uuid4()}")).status_code == 404
|
|
|
|
|
|
def test_get_volunteer_of_another_edition_is_404(client, edition, session):
|
|
from app.models import Edition
|
|
|
|
other = Edition(
|
|
year=2027,
|
|
start_date=dt.date(2027, 7, 1),
|
|
end_date=dt.date(2027, 7, 4),
|
|
)
|
|
session.add(other)
|
|
session.commit()
|
|
session.refresh(other)
|
|
stranger = make_volunteer(session, other, email="x@ex.fr")
|
|
|
|
assert client.get(_url(edition, f"/{stranger.id}")).status_code == 404
|
|
|
|
|
|
def test_create_with_artist_and_position_wishes(client, edition, session):
|
|
artist = make_artist(session, edition)
|
|
position = make_position(session, edition)
|
|
resp = client.post(
|
|
_url(edition),
|
|
json={
|
|
"first_name": "Fan",
|
|
"last_name": "Zele",
|
|
"artist_ids": [str(artist.id)],
|
|
"wished_position_ids": [str(position.id)],
|
|
},
|
|
)
|
|
assert resp.status_code == 201
|
|
body = resp.json()
|
|
assert body["artist_ids"] == [str(artist.id)]
|
|
assert body["wished_position_ids"] == [str(position.id)]
|
|
|
|
|
|
def test_unknown_artist_wish_is_422(client, edition):
|
|
resp = client.post(
|
|
_url(edition),
|
|
json={
|
|
"first_name": "A",
|
|
"last_name": "B",
|
|
"artist_ids": [str(uuid.uuid4())],
|
|
},
|
|
)
|
|
assert resp.status_code == 422
|
|
assert resp.json()["detail"]["code"] == "artist.unknown"
|
|
|
|
|
|
def test_patch_replaces_and_clears_wishes(client, edition, session):
|
|
a1 = make_artist(session, edition, name="A1")
|
|
a2 = make_artist(session, edition, name="A2")
|
|
volunteer = make_volunteer(session, edition, email="w@ex.fr")
|
|
|
|
r1 = client.patch(
|
|
_url(edition, f"/{volunteer.id}"),
|
|
json={"artist_ids": [str(a2.id), str(a1.id), str(a2.id)]},
|
|
)
|
|
# Doublons retirés, tri par (date, nom).
|
|
assert r1.json()["artist_ids"] == [str(a1.id), str(a2.id)]
|
|
|
|
r2 = client.patch(
|
|
_url(edition, f"/{volunteer.id}"), json={"artist_ids": []}
|
|
)
|
|
assert r2.json()["artist_ids"] == []
|
|
# Champ absent = inchangé.
|
|
r3 = client.patch(
|
|
_url(edition, f"/{volunteer.id}"), json={"first_name": "Zoe"}
|
|
)
|
|
assert r3.json()["artist_ids"] == []
|
|
|
|
|
|
def test_patch_updates_simple_fields(client, edition, session):
|
|
volunteer = make_volunteer(session, edition, email="p@ex.fr")
|
|
r1 = client.patch(
|
|
_url(edition, f"/{volunteer.id}"),
|
|
json={"first_name": "Neo", "comment": "dispo tôt"},
|
|
)
|
|
assert r1.status_code == 200
|
|
assert r1.json()["first_name"] == "Neo"
|
|
assert r1.json()["comment"] == "dispo tôt"
|
|
|
|
|
|
def test_delete_is_a_full_cascade(client, edition, session):
|
|
volunteer = make_volunteer(session, edition, email="gone@ex.fr")
|
|
position = make_position(session, edition)
|
|
shift = make_shift(
|
|
session, edition, position, start=dt_at(10, 9), end=dt_at(10, 12)
|
|
)
|
|
make_availability(
|
|
session,
|
|
edition,
|
|
volunteer,
|
|
date=dt.date(2026, 7, 10),
|
|
start_time=dt.time(8, 0),
|
|
end_time=dt.time(13, 0),
|
|
)
|
|
session.add(
|
|
Assignment(
|
|
edition_id=edition.id,
|
|
volunteer_id=volunteer.id,
|
|
shift_id=shift.id,
|
|
)
|
|
)
|
|
session.commit()
|
|
|
|
resp = client.delete(_url(edition, f"/{volunteer.id}"))
|
|
assert resp.status_code == 204
|
|
assert client.get(_url(edition, f"/{volunteer.id}")).status_code == 404
|
|
assert session.exec(select(Volunteer)).all() == []
|
|
assert session.exec(select(Assignment)).all() == []
|
|
assert session.exec(select(Availability)).all() == []
|
|
# Le créneau subsiste.
|
|
from app.models import Shift
|
|
|
|
assert session.get(Shift, shift.id) is not None
|