Bénévole : vœux d'artistes (entité Artist) et vœux de postes
Nouvelle entité `Artist` (nom + jour de passage), CRUD
`/editions/{id}/artists` (lecture ouverte à tout compte de l'édition,
écriture COORDINATION), unicité (édition, nom, date).
La fiche bénévole porte deux listes de vœux, sur le modèle de
`skill_codes` (None = inchangé, [] = vider) :
- `artist_ids` : artistes que le bénévole veut voir (`volunteer_artist`) ;
- `wished_position_ids` : postes qu'il voudrait tenir
(`volunteer_position_wish`), distinct de l'affectation.
Un id étranger à l'édition renvoie 422 (`artist.unknown` /
`position.unknown`). Suppression d'un artiste : cascade sur les vœux.
Migration 0006. Jeu de démonstration et frontend inchangés (le front
suivra).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
609514369a
commit
24caece7df
@@ -3,6 +3,7 @@
|
||||
import datetime as dt
|
||||
|
||||
from app.models import (
|
||||
Artist,
|
||||
Availability,
|
||||
AvailabilityStatus,
|
||||
Position,
|
||||
@@ -22,6 +23,18 @@ def make_position(session, edition, *, name="Bar", category=PositionCategory.BAR
|
||||
return position
|
||||
|
||||
|
||||
def make_artist(
|
||||
session, edition, *, name="Chilla", performance_date=dt.date(2026, 7, 10)
|
||||
):
|
||||
artist = Artist(
|
||||
edition_id=edition.id, name=name, performance_date=performance_date
|
||||
)
|
||||
session.add(artist)
|
||||
session.commit()
|
||||
session.refresh(artist)
|
||||
return artist
|
||||
|
||||
|
||||
def make_shift(
|
||||
session, edition, position, *, start, end, min_staff=1, ideal_staff=2, skills=()
|
||||
):
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import datetime as dt
|
||||
import uuid
|
||||
|
||||
from sqlmodel import select
|
||||
|
||||
from app.models import Artist, Role, VolunteerArtist
|
||||
from tests.factories import make_artist, make_volunteer
|
||||
|
||||
|
||||
def _url(edition, suffix=""):
|
||||
return f"/editions/{edition.id}/artists{suffix}"
|
||||
|
||||
|
||||
def test_create_and_list_ordered_by_date_then_name(client, edition):
|
||||
client.post(
|
||||
_url(edition), json={"name": "Ziak", "performance_date": "2026-07-11"}
|
||||
)
|
||||
client.post(
|
||||
_url(edition), json={"name": "Aloïse Sauvage", "performance_date": "2026-07-11"}
|
||||
)
|
||||
r = client.post(
|
||||
_url(edition), json={"name": "Chilla", "performance_date": "2026-07-10"}
|
||||
)
|
||||
assert r.status_code == 201
|
||||
|
||||
body = client.get(_url(edition)).json()
|
||||
assert [(a["name"], a["performance_date"]) for a in body] == [
|
||||
("Chilla", "2026-07-10"),
|
||||
("Aloïse Sauvage", "2026-07-11"),
|
||||
("Ziak", "2026-07-11"),
|
||||
]
|
||||
|
||||
|
||||
def test_blank_name_is_422(client, edition):
|
||||
r = client.post(
|
||||
_url(edition), json={"name": " ", "performance_date": "2026-07-10"}
|
||||
)
|
||||
assert r.status_code == 422
|
||||
assert r.json()["detail"]["code"] == "artist.name_required"
|
||||
|
||||
|
||||
def test_duplicate_name_and_date_conflicts(client, edition):
|
||||
payload = {"name": "Chilla", "performance_date": "2026-07-10"}
|
||||
assert client.post(_url(edition), json=payload).status_code == 201
|
||||
r = client.post(_url(edition), json=payload)
|
||||
assert r.status_code == 409
|
||||
assert r.json()["detail"]["code"] == "artist.duplicate"
|
||||
|
||||
# Même nom, autre jour : autorisé.
|
||||
r2 = client.post(
|
||||
_url(edition), json={"name": "Chilla", "performance_date": "2026-07-11"}
|
||||
)
|
||||
assert r2.status_code == 201
|
||||
|
||||
|
||||
def test_update_artist(client, edition, session):
|
||||
artist = make_artist(session, edition, name="Chila")
|
||||
r = client.patch(
|
||||
_url(edition, f"/{artist.id}"),
|
||||
json={"name": "Chilla", "performance_date": "2026-07-12"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["name"] == "Chilla"
|
||||
assert r.json()["performance_date"] == "2026-07-12"
|
||||
|
||||
|
||||
def test_delete_artist_removes_volunteer_wishes(client, edition, session):
|
||||
artist = make_artist(session, edition)
|
||||
volunteer = make_volunteer(session, edition, email="fan@e.fr")
|
||||
assert client.patch(
|
||||
f"/editions/{edition.id}/volunteers/{volunteer.id}",
|
||||
json={"artist_ids": [str(artist.id)]},
|
||||
).json()["artist_ids"] == [str(artist.id)]
|
||||
|
||||
assert client.delete(_url(edition, f"/{artist.id}")).status_code == 204
|
||||
assert session.exec(select(Artist)).all() == []
|
||||
assert session.exec(select(VolunteerArtist)).all() == []
|
||||
fiche = client.get(
|
||||
f"/editions/{edition.id}/volunteers/{volunteer.id}"
|
||||
).json()
|
||||
assert fiche["artist_ids"] == []
|
||||
|
||||
|
||||
def test_unknown_edition_is_404(client):
|
||||
assert client.get(f"/editions/{uuid.uuid4()}/artists").status_code == 404
|
||||
|
||||
|
||||
def test_write_is_coordinator_only(edition, make_account, as_account):
|
||||
lead = make_account(Role.LEAD, email="lead@e.fr")
|
||||
api = as_account(lead)
|
||||
resp = api.post(
|
||||
_url(edition), json={"name": "X", "performance_date": "2026-07-10"}
|
||||
)
|
||||
assert resp.status_code == 403
|
||||
# La lecture reste ouverte à tout compte de l'édition.
|
||||
assert api.get(_url(edition)).status_code == 200
|
||||
|
||||
|
||||
def test_other_edition_artist_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_artist(session, other, name="Ailleurs")
|
||||
|
||||
assert client.patch(
|
||||
_url(edition, f"/{stranger.id}"), json={"name": "Y"}
|
||||
).status_code == 404
|
||||
@@ -1,10 +1,12 @@
|
||||
import datetime as dt
|
||||
import uuid
|
||||
|
||||
from sqlmodel import select
|
||||
|
||||
from app.models import Assignment, Availability, AvailabilityStatus, Volunteer
|
||||
from tests.factories import (
|
||||
dt_at,
|
||||
make_artist,
|
||||
make_availability,
|
||||
make_position,
|
||||
make_shift,
|
||||
@@ -56,8 +58,6 @@ def test_list_is_ordered_by_name(client, edition, session):
|
||||
|
||||
|
||||
def test_get_unknown_id_is_404(client, edition):
|
||||
import uuid
|
||||
|
||||
assert client.get(_url(edition, f"/{uuid.uuid4()}")).status_code == 404
|
||||
|
||||
|
||||
@@ -77,6 +77,60 @@ def test_get_volunteer_of_another_edition_is_404(client, edition, session):
|
||||
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_replaces_skills_and_can_clear(client, edition, session):
|
||||
volunteer = make_volunteer(session, edition, email="p@ex.fr")
|
||||
r1 = client.patch(
|
||||
|
||||
@@ -22,8 +22,11 @@ EXPECTED_TABLES = {
|
||||
"edition",
|
||||
"day_part",
|
||||
"skill",
|
||||
"artist",
|
||||
"volunteer",
|
||||
"volunteer_skill",
|
||||
"volunteer_artist",
|
||||
"volunteer_position_wish",
|
||||
"account",
|
||||
"magic_link_token",
|
||||
"position",
|
||||
|
||||
Reference in New Issue
Block a user