def test_MultipleMafiaMembers_MustAgreeOnWhoToKill(): player1 = createVillager('test1') player2 = createVillager('test2') mafia1 = createMafia('mafia1') mafia2 = createMafia('mafia2') state = Game() state.state = GameStates.NIGHT state.players = [player1, player2, createVillager(), createVillager(), mafia1, mafia2] systemUnderTest = getInstance(state) #mafia 1 wants to kill player 1 systemUnderTest.transition(Actions.MURDER, player1.id, mafia1.id) assert state.state == GameStates.NIGHT assert player1.state == PlayerStates.ALIVE #mafia 2 wants to kill player 2 systemUnderTest.transition(Actions.MURDER, player2.id, mafia2.id) assert state.state == GameStates.NIGHT assert player1.state == PlayerStates.ALIVE assert player2.state == PlayerStates.ALIVE #mafia 1 decides to agree and kill player2 instead systemUnderTest.transition(Actions.MURDER, player2.id, mafia1.id) assert state.state == GameStates.DAY assert player2.state == PlayerStates.DEAD
def test_StartGame_CreatesChannelAndInvitesMafia(): repo = GameStateRepo() game = Game() testpId = 'test' testMafiaChannelId = 'testChannel' game.players = [createMafia(id=testpId)] game.state = States.NIGHT game.meta = {'channel_id': 'channel'} with patch('mafiaManageSlack.WebClient') as slackClientConstructor: with patch( 'mafiaManageSlack.get_state_change_message') as messageBuilder: with patch('data_access.dataRepos.boto3'): with patch('mafiaManageSlack.boto3'): slackClient = slackClientConstructor.return_value slackClient.conversations_create.return_value = { 'channel': { 'id': testMafiaChannelId } } mafiaManageSlack.lambda_handler( createSqsEvent({ 'state': repo._serializeGame(game), 'action': Actions.START_GAME, 'source': 'initiator', 'target': None }), None) slackClient.conversations_create.assert_called_with( name='mafia-secrets', is_private=True) slackClient.conversations_invite.assert_called_with( channel=testMafiaChannelId, users=testpId) slackClient.chat_postMessage.assert_called_with( channel=testMafiaChannelId, text= 'You are members of the local mafia. Rabble-rousers in the village have decided to make a stand against you. It is time you taught them a lesson...\nKill one of them using the command: /mafia kill @who-to-kill\nIf there is more than one member of the mafia you must all /mafia kill the same villager before they will be killed.' )
def test_GameStateNight_MurderAction_StateIsDayPlayerDead(): player = createVillager('test') mafia = createMafia('mafia') state = Game() state.state = GameStates.NIGHT state.players = [player, createVillager(), createVillager(), mafia] systemUnderTest = getInstance(state) systemUnderTest.transition(Actions.MURDER, player.id, mafia.id) assert state.state == GameStates.DAY assert player.state == PlayerStates.DEAD
def test_GameStateNight_MurderResultsInVillagerCountEqualingMafia_StateIsGameOver(): player = createVillager('test') mafia = createMafia('mafia') state = Game() state.state = GameStates.NIGHT state.players = [player, createVillager(), mafia] systemUnderTest = getInstance(state) systemUnderTest.transition(Actions.MURDER, player.id, mafia.id) assert state.state == GameStates.GAME_OVER assert player.state == PlayerStates.DEAD
def test_CanNotCastVoteIfOnTrial(): state = Game() state.state = GameStates.TRIAL systemUnderTest = getInstance(state) mafia = createMafia('test') villager1 = createVillager('v1') villager2 = createVillager('v2') mafia.state = PlayerStates.ON_TRIAL state.players = [mafia, villager1, villager2] systemUnderTest.transition(Actions.GUILTY, executor=mafia.id) assert mafia.vote == None
def test_VillagerCanNotMurder(): player1 = createVillager('test1') player2 = createVillager('test1') mafia = createMafia('mafia') state = Game() state.state = GameStates.NIGHT state.players = [player1, player2, mafia] systemUnderTest = getInstance(state) systemUnderTest.transition(Actions.MURDER, player2.id, player1.id) assert state.state == GameStates.NIGHT assert player2.state == PlayerStates.ALIVE
def test_GameStateTrial_LastMafiaMemberFoundGuilty_StateIsGameOver(): state = Game() state.state = GameStates.TRIAL systemUnderTest = getInstance(state) mafia = createMafia('test') villager1 = createVillager('v1') villager2 = createVillager('v2') mafia.state = PlayerStates.ON_TRIAL state.players = [mafia, villager1, villager2] systemUnderTest.transition(Actions.GUILTY, executor='v1') systemUnderTest.transition(Actions.GUILTY, executor='v2') assert state.state == GameStates.GAME_OVER assert mafia.state == PlayerStates.DEAD
def test_GameStateTrial_FoundGuiltyAction_StateIsNightPlayerOnTrialIsDead(): state = Game() state.state = GameStates.TRIAL systemUnderTest = getInstance(state) player = createVillager('test') villager1 = createVillager('v1') villager2 = createVillager('v2') mafia = createMafia('m') player.state = PlayerStates.ON_TRIAL state.players = [player, villager2, villager1, mafia] systemUnderTest.transition(Actions.NOT_GUILTY, executor='v1') systemUnderTest.transition(Actions.GUILTY, executor='v2') systemUnderTest.transition(Actions.GUILTY, executor='m') assert state.state == GameStates.NIGHT assert player.state == PlayerStates.DEAD
def test_GameStateTrial_FoundNotGuiltyAction_StateIsDayPlayerOnTrialIsAlive(): state = Game() state.state = GameStates.TRIAL systemUnderTest = getInstance(state) player = createVillager('test') villager1 = createVillager('v1') villager2 = createVillager('v2') villager3 = createVillager('v3') villager3.state = PlayerStates.DEAD mafia = createMafia('m') player.state = PlayerStates.ON_TRIAL state.players = [player, villager2, villager1, mafia, villager3] systemUnderTest.transition(Actions.GUILTY, executor='m') assert state.state == GameStates.TRIAL systemUnderTest.transition(Actions.NOT_GUILTY, executor='v1') assert state.state == GameStates.TRIAL systemUnderTest.transition(Actions.NOT_GUILTY, executor='v2') assert state.state == GameStates.DAY assert player.state == PlayerStates.ALIVE