def test_troop_proposal_not_leader_fail(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         mission = game.current_mission()
         with self.assertRaises(errors.NotLeader):
             game_manager.update_mission(mission, sid='-1', players_ids=[1])
         self.assertTrue(mission.stage == model.RoundStage.troop_proposal)
 def test_mission_vote_disapprove_success(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         mission = game.current_mission()
         game_manager.update_mission(mission, sid='1', result=False)
         self.assertTrue(mission.stage == model.RoundStage.mission_results)
         self.assertTrue(mission.voting.result is False)
 def test_mission_vote_approve_wrong_user_fail(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         mission = game.current_mission()
         with self.assertRaises(errors.CantVote):
             game_manager.update_mission(mission, sid='2', result=True)
         self.assertTrue(mission.stage == model.RoundStage.mission_voting)
         self.assertTrue(mission.voting.result is None)
 def test_troop_proposal_success(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         mission = game.current_mission()
         game_manager.update_mission(mission, sid=game.current_leader().sid, players_ids=[1])
         self.assertTrue(mission.stage == model.RoundStage.troop_voting)
         self.assertTrue(len(mission.current_voting().votes) == len(game.players))
         self.assertTrue(len(mission.troop_proposals[-1].members) == 1)
         self.assertTrue(mission.troop_proposals[-1].members[0].id == 1)
 def test_troop_vote_approve_success(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         mission = game.current_mission()
         game_manager.update_mission(mission, sid=game.current_leader().sid, players_ids=[1])
         game_manager.update_mission(mission, sid='1', result=True)
         game_manager.update_mission(mission, sid='2', result=True)
         game_manager.update_mission(mission, sid='3', result=True)
         self.assertTrue(mission.stage == model.RoundStage.mission_voting)
         self.assertTrue(mission.troop_proposals[-1].voting.result is True)
 def test_troop_vote_approve_twice_vote_fail(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         mission = game.current_mission()
         game_manager.update_mission(mission, sid=game.current_leader().sid, players_ids=[1])
         game_manager.update_mission(mission, sid='1', result=True)
         game_manager.update_mission(mission, sid='2', result=True)
         with self.assertRaises(errors.CantVote):
             game_manager.update_mission(mission, sid='2', result=True)
         self.assertTrue(mission.stage == model.RoundStage.troop_voting)
         self.assertTrue(mission.troop_proposals[-1].voting.result is None)
 def setUp(self):
     self.app = create_app('config.Test')
     with self.app.app_context():
         game = game_manager.create_game('test', '1')
         game_manager.join_game(game, 'test1', '2')
         game_manager.join_game(game, 'test2', '3')
         game_manager.update_game(game, sid='1')
         mission = game.current_mission()
         game_manager.update_mission(mission,
                                     sid=game.current_leader().sid,
                                     players_ids=[1])
         game_manager.update_mission(mission, sid='1', result=True)
         game_manager.update_mission(mission, sid='2', result=True)
         game_manager.update_mission(mission, sid='3', result=True)
         self.game_id = game.id
    def test_troop_vote_disapprove_mission_lose_success(self):
        with self.app.app_context():
            game = game_manager.request_game(self.game_id)
            mission = game.current_mission()
            game_manager.update_mission(mission, sid=game.current_leader().sid, players_ids=[1])
            game_manager.update_mission(mission, sid='1', result=True)
            game_manager.update_mission(mission, sid='2', result=False)
            game_manager.update_mission(mission, sid='3', result=False)

            game_manager.update_mission(mission, sid=game.current_leader().sid, players_ids=[1])
            game_manager.update_mission(mission, sid='1', result=True)
            game_manager.update_mission(mission, sid='2', result=False)
            game_manager.update_mission(mission, sid='3', result=False)

            self.assertTrue(mission.stage == model.RoundStage.mission_results)
            self.assertTrue(mission.resistance_won is False)
 def test_troop_proposal_wrong_troop_size_fail(self):
     with self.app.app_context():
         game = game_manager.request_game(self.game_id)
         with self.assertRaises(errors.InvalidPlayersNumber):
             game_manager.update_mission(game.current_mission(), sid=game.current_leader().sid, players_ids=[1, 2])
         self.assertTrue(game.current_mission().stage == model.RoundStage.troop_proposal)