def test_multiple_games(self): self.test_game_complete_resistance_won_success() with self.app.app_context(): game = game_manager.request_game(self.game_id) game = game_manager.new_game(game, sid=game.host.sid) self.game_id = game.id self.assertEqual(game.stage, model.GameStage.pending) game_manager.update_game(game, sid='1') self.assertEqual(game.stage, model.GameStage.executing_mission) game_manager.leave_game(game.id, '6', 6) game_manager.join_game(game, 'new', '6') self.assertEqual(game.stage, model.GameStage.pending) game_manager.update_game(game, sid='1') self.assertEqual(len(db.session.query(model.Game.id).all()), 2) self.assertEqual(len(db.session.query(model.Player.id).all()), 6) self.assertTrue(len(game.players), 6) self.test_game_complete_resistance_won_success() with self.app.app_context(): self.assertEqual(len(db.session.query(model.Game.id).all()), 2) self.assertEqual(len(db.session.query(model.Player.id).all()), 6) self.assertTrue(len(game.players), 6)
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) game_manager.leave_game(game.id, '2', 2) game_manager.join_game(game, 'test1', '2') 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_leave_game_host_success(self): with self.app.app_context(): game = game_manager.create_game('test', '1') game_manager.join_game(game, 'test1', '2') game_manager.leave_game(game.id, '1', 1) self.assertTrue(len(db.session.query(model.Game).all()) == 0) self.assertTrue(len(db.session.query(model.Player).all()) == 0)
def test_kick_player_non_host_fail(self): with self.app.app_context(): with self.assertRaises(errors.ForbiddenAction): game = game_manager.create_game('test', '1') game_manager.join_game(game, 'test1', '2') game_manager.leave_game(game.id, '2', 1) self.assertTrue( len( db.session.query(model.Player).filter( model.Player.game_id == game.id).all()) == 2)
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') game_manager.leave_game(game.id, '2', 2) game_manager.join_game(game, 'test1', '2') game_manager.update_game(game, sid='1') self.game_id = game.id
def test_leave_game_started_success(self): 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') self.assertTrue(game.stage != model.GameStage.pending) game_manager.leave_game(game.id, '2', 2) self.assertTrue(game.stage == model.GameStage.pending) self.assertTrue(len(game.missions) == 0) self.assertTrue(len(game.players) == 2) game_manager.join_game(game, 'test1', '2') game_manager.update_game(game, sid='1') self.assertTrue(game.stage != model.GameStage.pending)