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
95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
import datetime as dt
|
|
|
|
from tests.factories import make_position
|
|
|
|
|
|
def _url(edition, suffix=""):
|
|
return f"/editions/{edition.id}/shifts{suffix}"
|
|
|
|
|
|
def _payload(position, **overrides):
|
|
base = {
|
|
"position_id": str(position.id),
|
|
"starts_at": "2026-07-10T18:00:00",
|
|
"ends_at": "2026-07-10T22:00:00",
|
|
"min_staff": 2,
|
|
"ideal_staff": 4,
|
|
}
|
|
base.update(overrides)
|
|
return base
|
|
|
|
|
|
def test_create_shift(client, edition, session):
|
|
position = make_position(session, edition)
|
|
resp = client.post(_url(edition), json=_payload(position))
|
|
assert resp.status_code == 201
|
|
body = resp.json()
|
|
assert body["min_staff"] == 2
|
|
assert body["position_id"] == str(position.id)
|
|
|
|
|
|
def test_create_shift_end_before_start_is_422(client, edition, session):
|
|
position = make_position(session, edition)
|
|
resp = client.post(
|
|
_url(edition),
|
|
json=_payload(position, ends_at="2026-07-10T17:00:00"),
|
|
)
|
|
assert resp.status_code == 422
|
|
assert resp.json()["detail"]["code"] == "shift.ends_not_after_starts"
|
|
|
|
|
|
def test_create_shift_with_position_from_other_edition_is_422(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_position = make_position(session, other)
|
|
|
|
resp = client.post(_url(edition), json=_payload(stranger_position))
|
|
assert resp.status_code == 422
|
|
assert resp.json()["detail"]["code"] == "shift.position_wrong_edition"
|
|
|
|
|
|
def test_list_filter_by_position(client, edition, session):
|
|
p1 = make_position(session, edition, name="P1")
|
|
p2 = make_position(session, edition, name="P2")
|
|
client.post(_url(edition), json=_payload(p1))
|
|
client.post(
|
|
_url(edition),
|
|
json=_payload(
|
|
p2,
|
|
starts_at="2026-07-11T09:00:00",
|
|
ends_at="2026-07-11T12:00:00",
|
|
),
|
|
)
|
|
|
|
only_p1 = client.get(_url(edition), params={"position_id": str(p1.id)}).json()
|
|
assert len(only_p1) == 1
|
|
assert only_p1[0]["position_id"] == str(p1.id)
|
|
assert len(client.get(_url(edition)).json()) == 2
|
|
|
|
|
|
def test_patch_shift_times(client, edition, session):
|
|
position = make_position(session, edition)
|
|
sid = client.post(_url(edition), json=_payload(position)).json()["id"]
|
|
|
|
patched = client.patch(
|
|
_url(edition, f"/{sid}"),
|
|
json={"ends_at": "2026-07-10T23:30:00"},
|
|
)
|
|
assert patched.status_code == 200
|
|
assert patched.json()["ends_at"] == "2026-07-10T23:30:00"
|
|
|
|
|
|
def test_patch_shift_into_invalid_range_is_422(client, edition, session):
|
|
position = make_position(session, edition)
|
|
sid = client.post(_url(edition), json=_payload(position)).json()["id"]
|
|
resp = client.patch(
|
|
_url(edition, f"/{sid}"), json={"starts_at": "2026-07-11T00:00:00"}
|
|
)
|
|
assert resp.status_code == 422
|