Require Gat descriptions and keep them consistent across ownership changes
This commit is contained in:
@@ -2886,3 +2886,101 @@ def test_completed_obstacle_still_awards_deferred_draw(session):
|
||||
assert crud.get_player_hand(rat) == []
|
||||
assert crud.resolve_challenge(session, challenge.id, deep.id)[0]
|
||||
assert crud.get_player_hand(rat) == ['AD']
|
||||
|
||||
|
||||
@pytest.mark.parametrize("description", ["", " \t\n", "\x00\x07"])
|
||||
def test_gat_description_rejects_blank_input(session, description):
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
from pirats.database import get_session
|
||||
from pirats.routes_scene import router
|
||||
|
||||
game, deep, (rat,) = make_scene_game(session, num_pirats=1)
|
||||
crud.toggle_objective(session, game.id, rat.id, "personal_1", True)
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
app.dependency_overrides[get_session] = lambda: session
|
||||
with TestClient(app) as client:
|
||||
response = client.post(
|
||||
f"/game/{game.id}/player/{rat.id}/set-gat-description",
|
||||
data={"description": description},
|
||||
)
|
||||
assert response.status_code in (400, 422)
|
||||
session.refresh(rat)
|
||||
assert rat.gat_description == ""
|
||||
assert rat.needs_gat_description
|
||||
|
||||
|
||||
def test_gat_description_saved_and_shared_with_crew(session):
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
from pirats.database import get_session
|
||||
from pirats.main import get_game_state
|
||||
from pirats.routes_scene import router
|
||||
|
||||
game, deep, (rat,) = make_scene_game(session, num_pirats=1)
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
app.dependency_overrides[get_session] = lambda: session
|
||||
path = f"/game/{game.id}/player/{rat.id}/set-gat-description"
|
||||
with TestClient(app) as client:
|
||||
assert client.post(path, data={"description": "Cutlass"}).status_code == 400
|
||||
# Older Gats may be missing a description without a pending prompt flag.
|
||||
rat.completed_personal_1 = True
|
||||
session.add(rat)
|
||||
session.commit()
|
||||
assert client.post(
|
||||
f"/game/wrong-game/player/{rat.id}/set-gat-description",
|
||||
data={"description": "Cutlass"},
|
||||
).status_code == 404
|
||||
assert client.post(path, data={"description": " Pearl\x00-handled flintlock "}).status_code == 200
|
||||
session.refresh(rat)
|
||||
assert rat.gat_description == "Pearl-handled flintlock"
|
||||
assert not rat.needs_gat_description
|
||||
own_state = get_game_state(game.id, rat.id, session)
|
||||
crew_state = get_game_state(game.id, deep.id, session)
|
||||
assert own_state["player"]["gat_description"] == rat.gat_description
|
||||
assert next(p for p in crew_state["players"] if p["id"] == rat.id)["gat_description"] == rat.gat_description
|
||||
|
||||
|
||||
@pytest.mark.parametrize("description", ["A rusty cutlass", ""])
|
||||
def test_gat_description_and_prompt_follow_tax_transfer(session, description):
|
||||
game, deep, (requester, owner) = make_scene_game(session, num_pirats=2)
|
||||
obstacle = game.obstacles[0]
|
||||
obstacle.current_value = 13
|
||||
owner.completed_personal_1 = True
|
||||
owner.gat_description = description
|
||||
owner.needs_gat_description = not bool(description)
|
||||
requester.hand_cards = json.dumps(["2C"])
|
||||
session.add_all([obstacle, requester, owner])
|
||||
session.commit()
|
||||
assert crud.create_challenge(session, game.id, deep.id, requester.id, [obstacle.id])[0]
|
||||
session.refresh(game)
|
||||
challenge = game.challenges[0]
|
||||
assert crud.request_tax(session, challenge.id, requester.id, owner.id)[0]
|
||||
assert crud.respond_tax(session, challenge.id, owner.id, accept=False)[0]
|
||||
assert requester.gat_description == description
|
||||
assert requester.needs_gat_description == (not bool(description))
|
||||
assert owner.gat_description == ""
|
||||
assert not owner.needs_gat_description
|
||||
assert crud.play_challenge_card(session, requester.id, obstacle.id, "2C")[0]
|
||||
assert crud.resolve_challenge(session, challenge.id, deep.id)[0]
|
||||
assert owner.gat_description == description
|
||||
assert owner.needs_gat_description == (not bool(description))
|
||||
assert requester.gat_description == ""
|
||||
assert not requester.needs_gat_description
|
||||
|
||||
|
||||
@pytest.mark.parametrize("description", ["A rusty cutlass", ""])
|
||||
def test_recruit_clears_previous_gat(session, description):
|
||||
game, deep, (rat,) = make_scene_game(session, num_pirats=1)
|
||||
rat.completed_personal_1 = True
|
||||
rat.gat_description = description
|
||||
rat.needs_gat_description = not bool(description)
|
||||
session.add(rat)
|
||||
session.commit()
|
||||
crud.activate_recruit(session, game, rat)
|
||||
session.refresh(rat)
|
||||
assert not rat.completed_personal_1
|
||||
assert rat.gat_description == ""
|
||||
assert not rat.needs_gat_description
|
||||
|
||||
Reference in New Issue
Block a user