def test_priest_works(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_id = uuid() priest_id = uuid() villager1_id = uuid() villager2_id = uuid() game.join(wolf_id) game.join(priest_id) game.join(villager1_id) game.join(villager2_id) game.join(uuid()) game.join(uuid()) game.start_game() with pytest.raises(HTTPException): game.priest_night_action(priest_id, villager1_id) game.wolf_night_action(wolf_id, villager1_id) assert game.get_player_model(villager1_id).state == PlayerState.WOLFED game._set_stage(GameStage.NIGHT) game.priest_night_action(priest_id, villager1_id) game.wolf_night_action(wolf_id, villager2_id) summary = get_summary_of_chat(game, priest_id) assert re.search(r"You remember that .+ was a Villager", summary)
def test_fool_no_mention_seer(empty_game): from unittest.mock import patch import backend from backend.roles import DistributionSettings game = WurwolvesGame("test_game") # Make some players in a game num_players = 10 user_ids = [uuid() for _ in range(num_players)] [game.join(u) for u in user_ids] # Customise the probabilitites to get a fool settings = DistributionSettings(role_weights={PlayerRole.FOOL: 1000000}) game.set_game_config(settings) game.start_game() # Find the fool (there's almost certainly one) fool_player = [p for p in game.get_players() if p.role == PlayerRole.FOOL] assert len(fool_player) == 1 fool_id = fool_player[0].user_id game.set_user_name(fool_id, "The one who isn't the seer") game._session.commit() # Confirm that the fool's state doesn't mention the fool anywhere def fool_in_state(fool_state): # Unfortunately, it does in one place: the function call. A savvy user could # therefore cheat. I should change it so that all player actions call the # same function in game. The game would then pass the call on to the # appropriate method, depending on the player's role. # For now, so this test passes, remove that reference fool_state_filtered = fool_state.dict() fool_state_filtered["controls_state"]["button_submit_func"] = "removed" fool_state = type(fool_state).parse_obj(fool_state_filtered) print("Fool state:") from pprint import pprint pprint(fool_state.dict()) return "fool" in fool_state.json().lower() game._set_stage(GameStage.NIGHT) fool_state = game.parse_game_to_state(fool_id) assert not fool_in_state(fool_state) game._set_stage(GameStage.VOTING) fool_state = game.parse_game_to_state(fool_id) assert not fool_in_state(fool_state) game._set_stage(GameStage.DAY) fool_state = game.parse_game_to_state(fool_id) assert not fool_in_state(fool_state) # Move to the end of the game and confirm that the fool is revealed game._set_stage(GameStage.ENDED) fool_state = game.parse_game_to_state(fool_id) assert fool_in_state(fool_state)