Advance after final rank vote and allow ballot changes
This commit is contained in:
+67
-1
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
import json
|
||||
from sqlmodel import SQLModel, create_engine, Session, select
|
||||
from sqlalchemy.pool import StaticPool
|
||||
from pirats import cards
|
||||
from pirats import crud
|
||||
from pirats.models import Game, Obstacle, Player, Challenge, GameEvent, Checkpoint
|
||||
@@ -8,7 +9,7 @@ from pirats.models import Game, Obstacle, Player, Challenge, GameEvent, Checkpoi
|
||||
# In-memory database for testing
|
||||
@pytest.fixture(name="session")
|
||||
def session_fixture():
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
@@ -1128,6 +1129,8 @@ def test_vote_validation(session):
|
||||
p1 = crud.add_player(session, game.id, "P1")
|
||||
p2 = crud.add_player(session, game.id, "P2")
|
||||
p3 = crud.add_player(session, game.id, "P3")
|
||||
game.phase = "between_scenes"
|
||||
session.add(game)
|
||||
p1.role = "deep"
|
||||
p2.role = "pirat"
|
||||
p3.role = "pirat"
|
||||
@@ -2585,3 +2588,66 @@ def test_request_body_size_limit_on_real_app():
|
||||
client = TestClient(app)
|
||||
r = client.post("/api/game", content=b"x" * (DEFAULT_MAX_BODY_BYTES + 1))
|
||||
assert r.status_code == 413
|
||||
|
||||
|
||||
def test_votes_can_change_until_final_vote_then_close(session):
|
||||
game, deep, (a, b) = make_scene_game(session, num_pirats=2)
|
||||
crud.end_scene_and_transition(session, game.id)
|
||||
assert crud.submit_rank_vote(session, game.id, deep.id, a.id)[0]
|
||||
assert crud.submit_rank_vote(session, game.id, deep.id, b.id)[0]
|
||||
session.refresh(game)
|
||||
assert len(game.votes) == 1
|
||||
assert game.votes[0].nominated_player_id == b.id
|
||||
assert game.phase == "between_scenes"
|
||||
assert crud.submit_rank_vote(session, game.id, a.id, b.id)[0]
|
||||
old_rank = b.rank
|
||||
assert crud.submit_rank_vote(session, game.id, b.id, a.id)[0]
|
||||
session.refresh(game)
|
||||
assert game.phase == "deep_upkeep"
|
||||
assert game.last_rank_up_player_id == b.id
|
||||
assert b.rank == old_rank + 1
|
||||
assert not crud.submit_rank_vote(session, game.id, deep.id, a.id)[0]
|
||||
crud.maybe_transition_to_deep_upkeep(session, game)
|
||||
assert b.rank == old_rank + 1
|
||||
|
||||
|
||||
def test_vote_skips_sole_nominee_and_advances_without_ready(session):
|
||||
game, deep, (a,) = make_scene_game(session)
|
||||
crud.end_scene_and_transition(session, game.id)
|
||||
assert crud.eligible_vote_nominees(game, a) == []
|
||||
assert crud.submit_rank_vote(session, game.id, deep.id, a.id)[0]
|
||||
assert game.phase == "deep_upkeep"
|
||||
assert game.last_rank_up_player_id == a.id
|
||||
|
||||
|
||||
def test_voting_waits_for_death_choice_and_skips_empty_ballots(session):
|
||||
game, deep, (a,) = make_scene_game(session)
|
||||
a.is_dead = True
|
||||
session.add(a)
|
||||
session.commit()
|
||||
crud.end_scene_and_transition(session, game.id)
|
||||
assert game.phase == "between_scenes"
|
||||
assert crud.choose_reroll(session, a.id)[0]
|
||||
assert game.phase == "deep_upkeep"
|
||||
assert game.last_rank_up_player_id is None
|
||||
|
||||
|
||||
def test_vote_result_survives_skipping_deep_upkeep(session):
|
||||
game, deep, (a,) = make_scene_game(session)
|
||||
deep.previous_role = None
|
||||
session.add(deep)
|
||||
session.commit()
|
||||
crud.end_scene_and_transition(session, game.id)
|
||||
assert crud.submit_rank_vote(session, game.id, deep.id, a.id)[0]
|
||||
assert game.phase == "scene_setup"
|
||||
assert game.last_rank_up_player_id == a.id
|
||||
|
||||
|
||||
def test_kick_last_pending_voter_completes_voting(session):
|
||||
game, deep, (a, b) = make_scene_game(session, num_pirats=2)
|
||||
crud.end_scene_and_transition(session, game.id)
|
||||
assert crud.submit_rank_vote(session, game.id, deep.id, a.id)[0]
|
||||
assert crud.submit_rank_vote(session, game.id, a.id, b.id)[0]
|
||||
assert crud.kick_player(session, game, b)[0]
|
||||
assert game.phase == "deep_upkeep"
|
||||
assert game.last_rank_up_player_id == a.id
|
||||
|
||||
Reference in New Issue
Block a user