Fix backend imports and clip pinning flow
This commit is contained in:
@@ -135,7 +135,7 @@ def test_walkup_session_selection_is_persisted_in_session() -> None:
|
||||
assert response.json()["external_player_id"] == "player-1002"
|
||||
|
||||
|
||||
def test_player_can_attach_multiple_clips_to_same_game() -> None:
|
||||
def test_player_can_pin_a_clip_to_multiple_games_independently() -> None:
|
||||
login = client.post("/auth/admin/login", json={"username": "admin", "password": "admin"})
|
||||
assert login.status_code == 200
|
||||
|
||||
@@ -159,18 +159,9 @@ def test_player_can_attach_multiple_clips_to_same_game() -> None:
|
||||
normalization_status="ready",
|
||||
normalized_path="clips/intro.mp3",
|
||||
)
|
||||
second_clip = AudioClip(
|
||||
asset_id=asset.id,
|
||||
label="Chorus",
|
||||
start_ms=12000,
|
||||
end_ms=22000,
|
||||
normalization_status="ready",
|
||||
normalized_path="clips/chorus.mp3",
|
||||
)
|
||||
db.add_all([first_clip, second_clip])
|
||||
db.add(first_clip)
|
||||
db.commit()
|
||||
db.refresh(first_clip)
|
||||
db.refresh(second_clip)
|
||||
db.close()
|
||||
|
||||
first_response = client.post(
|
||||
@@ -183,28 +174,68 @@ def test_player_can_attach_multiple_clips_to_same_game() -> None:
|
||||
"status": "ready",
|
||||
},
|
||||
)
|
||||
second_response = client.post(
|
||||
"/games/game-1/assignments",
|
||||
second_game_response = client.post(
|
||||
"/games/game-2/assignments",
|
||||
json={
|
||||
"external_team_id": "team-1",
|
||||
"external_player_id": "player-1",
|
||||
"clip_id": second_clip.id,
|
||||
"clip_id": first_clip.id,
|
||||
"batting_slot": 1,
|
||||
"status": "ready",
|
||||
},
|
||||
)
|
||||
|
||||
assert first_response.status_code == 200
|
||||
assert second_response.status_code == 200
|
||||
assert second_game_response.status_code == 200
|
||||
assert first_response.json()["start_ms"] == 0
|
||||
assert first_response.json()["end_ms"] == 10000
|
||||
assert second_response.json()["start_ms"] == 12000
|
||||
assert second_response.json()["end_ms"] == 22000
|
||||
|
||||
assignments = client.get("/games/game-1/assignments")
|
||||
assert assignments.status_code == 200
|
||||
assignment_ids = [item["clip_id"] for item in assignments.json()]
|
||||
assert assignment_ids == [second_clip.id, first_clip.id]
|
||||
game_one_assignments = client.get("/games/game-1/assignments")
|
||||
game_two_assignments = client.get("/games/game-2/assignments")
|
||||
assert game_one_assignments.status_code == 200
|
||||
assert game_two_assignments.status_code == 200
|
||||
assert [item["clip_id"] for item in game_one_assignments.json()] == [first_clip.id]
|
||||
assert [item["clip_id"] for item in game_two_assignments.json()] == [first_clip.id]
|
||||
|
||||
db = SessionLocal()
|
||||
session = db.query(UserSession).filter_by(session_token="admin-session").one_or_none()
|
||||
if session is None:
|
||||
session = UserSession(
|
||||
session_token="admin-session",
|
||||
provider="teamsnap",
|
||||
external_team_id="team-1",
|
||||
external_player_id="player-1",
|
||||
)
|
||||
db.add(session)
|
||||
db.commit()
|
||||
else:
|
||||
session.external_team_id = "team-1"
|
||||
session.external_player_id = "player-1"
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
client.cookies.set(settings.session_cookie_name, "admin-session")
|
||||
pins_before_delete = client.get("/games/pins", params={"external_player_id": "player-1"})
|
||||
assert pins_before_delete.status_code == 200
|
||||
assert [item["clip_id"] for item in pins_before_delete.json()] == [first_clip.id, first_clip.id]
|
||||
|
||||
delete_response = client.delete(
|
||||
f"/games/game-1/assignments/{first_response.json()['id']}",
|
||||
params={"external_player_id": "player-1"},
|
||||
)
|
||||
assert delete_response.status_code == 204
|
||||
|
||||
game_one_after_delete = client.get("/games/game-1/assignments")
|
||||
game_two_after_delete = client.get("/games/game-2/assignments")
|
||||
assert game_one_after_delete.status_code == 200
|
||||
assert game_two_after_delete.status_code == 200
|
||||
assert game_one_after_delete.json() == []
|
||||
assert [item["clip_id"] for item in game_two_after_delete.json()] == [first_clip.id]
|
||||
|
||||
client.cookies.set(settings.session_cookie_name, "admin-session")
|
||||
pins = client.get("/games/pins", params={"external_player_id": "player-1"})
|
||||
assert pins.status_code == 200
|
||||
assert [item["clip_id"] for item in pins.json()] == [first_clip.id]
|
||||
|
||||
|
||||
def test_upload_creates_default_clip_and_clip_ranges_can_be_updated() -> None:
|
||||
@@ -248,6 +279,73 @@ def test_upload_creates_default_clip_and_clip_ranges_can_be_updated() -> None:
|
||||
assert updated_clip["label"] == "Fresh track"
|
||||
|
||||
|
||||
def test_player_can_reorder_clips_in_their_library() -> None:
|
||||
db = SessionLocal()
|
||||
session = UserSession(
|
||||
session_token="player-session",
|
||||
provider="teamsnap",
|
||||
external_team_id="team-9",
|
||||
external_player_id="player-9",
|
||||
)
|
||||
db.add(session)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
client.cookies.set(settings.session_cookie_name, "player-session")
|
||||
|
||||
asset = AudioAsset(
|
||||
external_team_id="team-9",
|
||||
owner_external_player_id="player-9",
|
||||
title="Song",
|
||||
original_filename="song.mp3",
|
||||
mime_type="audio/mpeg",
|
||||
size_bytes=123,
|
||||
storage_path="uploads/song.mp3",
|
||||
)
|
||||
db = SessionLocal()
|
||||
db.add(asset)
|
||||
db.flush()
|
||||
first_clip = AudioClip(
|
||||
asset_id=asset.id,
|
||||
label="Intro",
|
||||
start_ms=0,
|
||||
end_ms=10000,
|
||||
sort_order=0,
|
||||
normalization_status="ready",
|
||||
normalized_path="clips/intro.mp3",
|
||||
)
|
||||
second_clip = AudioClip(
|
||||
asset_id=asset.id,
|
||||
label="Chorus",
|
||||
start_ms=12000,
|
||||
end_ms=22000,
|
||||
sort_order=1,
|
||||
normalization_status="ready",
|
||||
normalized_path="clips/chorus.mp3",
|
||||
)
|
||||
db.add_all([first_clip, second_clip])
|
||||
db.commit()
|
||||
db.refresh(first_clip)
|
||||
db.refresh(second_clip)
|
||||
db.close()
|
||||
|
||||
reorder = client.post(
|
||||
"/media/clips/reorder",
|
||||
json={
|
||||
"external_team_id": "team-9",
|
||||
"owner_external_player_id": "player-9",
|
||||
"clip_ids": [second_clip.id, first_clip.id],
|
||||
},
|
||||
)
|
||||
|
||||
assert reorder.status_code == 204
|
||||
|
||||
clips = client.get("/media/clips", params={"external_team_id": "team-9", "owner_external_player_id": "player-9"})
|
||||
assert clips.status_code == 200
|
||||
assert [item["id"] for item in clips.json()] == [second_clip.id, first_clip.id]
|
||||
assert [item["sort_order"] for item in clips.json()] == [0, 1]
|
||||
|
||||
|
||||
def test_clip_updates_can_use_player_scoped_authorization() -> None:
|
||||
uploader_session = UserSession(session_token="uploader-session", provider="teamsnap")
|
||||
editor_session = UserSession(session_token="editor-session", provider="teamsnap")
|
||||
|
||||
Reference in New Issue
Block a user