def test_prostitute_prevents_seer(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_id = uuid() seer_id = uuid() prostitute_id = uuid() villager_id = uuid() game.join(wolf_id) game.join(seer_id) game.join(prostitute_id) game.join(villager_id) game.join(uuid()) game.join(uuid()) game.start_game() # Seer checks villager but prostitute sleeps with seer. # Wolf kills villager, so villager dies game.prostitute_night_action(prostitute_id, seer_id) game.seer_night_action(seer_id, villager_id) game.wolf_night_action(wolf_id, villager_id) assert game.get_player_model(villager_id).state == PlayerState.WOLFED summary = get_summary_of_chat(game, seer_id) assert re.search(r"you couldn't concentrate", summary)
def test_seer_saved_no_fail(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_id = uuid() medic_id = uuid() seer_id = uuid() villager_id = uuid() game.join(wolf_id) game.join(medic_id) game.join(seer_id) game.join(villager_id) game.join(uuid()) game.join(uuid()) game.start_game() game.seer_night_action(seer_id, wolf_id) game.wolf_night_action(wolf_id, seer_id) game.medic_night_action(medic_id, seer_id) assert game.get_player_model(seer_id).state == PlayerState.ALIVE summary = get_summary_of_chat(game, seer_id) assert re.search(r"they are a wolf", summary)
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_killed_twice(db_session): game = WurwolvesGame(GAME_ID) # Add four players player_ids = [uuid() for _ in range(4)] roles = [ PlayerRole.VILLAGER, PlayerRole.VILLAGER, PlayerRole.VIGILANTE, PlayerRole.WOLF, ] for p in player_ids: game.join(p) game.start_game() for p, r in zip(player_ids, roles): game.set_player_role(game.get_player_id(p), r) villager1_id = player_ids[0] villager2_id = player_ids[1] vigilante_id = player_ids[2] wolf_id = player_ids[3] # Kill a villager with the vigilante game.vigilante_night_action(vigilante_id, villager1_id) # ...and the wolf game.wolf_night_action(wolf_id, villager1_id) # Check that the player retains their role db_session.expire_all() assert game.get_player_model( villager1_id).previous_role != PlayerRole.SPECTATOR
def test_prostitute_dooms_villager(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_id = uuid() prostitute_id = uuid() villager_id = uuid() game.join(wolf_id) game.join(prostitute_id) game.join(villager_id) game.join(uuid()) game.join(uuid()) game.join(uuid()) game.start_game() # Prostitute sleeps with villager, wolf attacks prostitute. # Both die. game.prostitute_night_action(prostitute_id, villager_id) game.wolf_night_action(wolf_id, prostitute_id) assert game.get_player_model(villager_id).state == PlayerState.WOLFED assert game.get_player_model(prostitute_id).state == PlayerState.WOLFED
def test_prostitute_saves_villager(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_id = uuid() prostitute_id = uuid() villager_id = uuid() game.join(wolf_id) game.join(prostitute_id) game.join(villager_id) game.join(uuid()) game.join(uuid()) game.join(uuid()) game.start_game() # Prostitute sleep with villager, wolf attacks villager. # Villager isn't home, so doesn't die game.prostitute_night_action(prostitute_id, villager_id) game.wolf_night_action(wolf_id, villager_id) assert game.get_player_model(villager_id).state == PlayerState.ALIVE
def test_prostitute_prevents_only_one_wolf_alt(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_1_id = uuid() wolf_2_id = uuid() prostitute_id = uuid() villager_id = uuid() game.join(wolf_1_id) game.join(wolf_2_id) game.join(prostitute_id) game.join(villager_id) game.join(uuid()) game.join(uuid()) game.join(uuid()) game.start_game() # Prostitute sleep with wolf 1, wolves attack villager. # First wolf if disabled but second wolf kills game.prostitute_night_action(prostitute_id, wolf_1_id) game.wolf_night_action(wolf_2_id, villager_id) assert game.get_player_model(villager_id).state == PlayerState.WOLFED
def test_prostitute_prevents_medic(mock_roles, db_session): game = WurwolvesGame("test_game") wolf_id = uuid() medic_id = uuid() prostitute_id = uuid() villager_id = uuid() game.join(wolf_id) game.join(medic_id) game.join(prostitute_id) game.join(villager_id) game.join(uuid()) game.join(uuid()) game.start_game() # Medic saves villager but prostitute sleeps with medic. # Wolf kills villager, so villager dies game.prostitute_night_action(prostitute_id, medic_id) game.medic_night_action(medic_id, villager_id) game.wolf_night_action(wolf_id, villager_id) assert game.get_player_model(villager_id).state == PlayerState.WOLFED
def test_kick_with_actions(db_session): game = WurwolvesGame(GAME_ID) # Add four players player_ids = [uuid() for _ in range(4)] roles = [ PlayerRole.MEDIC, PlayerRole.VILLAGER, PlayerRole.SPECTATOR, PlayerRole.WOLF, ] for p in player_ids: game.join(p) db_session = game._session game.start_game() for p, r in zip(player_ids, roles): game.set_player_role(game.get_player_id(p), r) timeout_player_id = player_ids[0] villager_id = player_ids[1] spectator_id = player_ids[2] wolf_id = player_ids[3] # Set one to have joined ages ago timeout_player = game.get_player(timeout_player_id) db_session.add(timeout_player) timeout_player.last_seen = datetime(1, 1, 1) db_session.commit() db_session.expire_all() timeout_player = game.get_player(timeout_player_id) db_session.add(timeout_player) assert timeout_player.state == PlayerState.ALIVE # Keepalive one of the other players, which should not kick the idler since it's a game game.player_keepalive(wolf_id) db_session.expire_all() assert game.get_player(timeout_player_id) # Kill the idler with the wolf game.wolf_night_action(wolf_id, timeout_player_id) # Have the idler do something too game.medic_night_action(timeout_player_id, wolf_id) db_session.expire_all() # Check game ended assert game.get_game_model().stage == GameStage.ENDED # Keepalive someone else game.player_keepalive(wolf_id) # Player should not yet be kicked db_session.expire_all() g = game.get_player(timeout_player_id) assert g # Put their timeout back into the past timeout_player.last_seen = datetime(1, 1, 1) db_session.commit() db_session.expire_all() # Keepalive someone else game.player_keepalive(wolf_id) # They still should be visible, but marked as inactive now db_session.expire_all() assert game.get_player(timeout_player_id) assert not game.get_player_model(timeout_player_id).active # Vote to start a new game game.wolf_ended_action(wolf_id) # Check a new game started db_session.expire_all() assert game.get_game_model().stage == GameStage.LOBBY # Check the idler was kicked after the next keepalive game.player_keepalive(wolf_id) assert not game.get_player(timeout_player_id)