async def test_start_game_with_teams( ladder_service: LadderService, game_service: GameService, player_factory, monkeypatch ): queue = ladder_service.queues["tmm2v2"] p1 = player_factory("Dostya", player_id=1, with_lobby_connection=True) p2 = player_factory("Rhiza", player_id=2, with_lobby_connection=True) p3 = player_factory("QAI", player_id=3, with_lobby_connection=True) p4 = player_factory("Hall", player_id=4, with_lobby_connection=True) game_service.ladder_maps = [(1, "scmp_007", "maps/scmp_007.zip")] monkeypatch.setattr(LadderGame, "wait_hosted", CoroutineMock()) monkeypatch.setattr(LadderGame, "wait_launched", CoroutineMock()) await ladder_service.start_game([p1, p3], [p2, p4], queue) game = game_service[game_service.game_id_counter] assert p1.lobby_connection.launch_game.called assert p2.lobby_connection.launch_game.called assert p3.lobby_connection.launch_game.called assert p4.lobby_connection.launch_game.called assert isinstance(game, LadderGame) assert game.rating_type == queue.rating_type assert game.max_players == 4 LadderGame.wait_launched.assert_called_once()
async def test_start_game(ladder_service: LadderService, game_service: GameService): p1 = mock.create_autospec(Player("Dostya", id=1)) p2 = mock.create_autospec(Player("Rhiza", id=2)) game_service.ladder_maps = [(1, "scmp_007", "maps/scmp_007.zip")] with mock.patch("asyncio.sleep", CoroMock()): await ladder_service.start_game(p1, p2) assert p1.lobby_connection.launch_game.called assert p2.lobby_connection.launch_game.called
async def test_start_game(ladder_service: LadderService, game_service: GameService): p1 = mock.create_autospec(Player('Dostya', id=1)) p2 = mock.create_autospec(Player('Rhiza', id=2)) game_service.ladder_maps = [(1, 'scmp_007', 'maps/scmp_007.zip')] with mock.patch('asyncio.sleep', CoroMock()): await ladder_service.start_game(p1, p2) assert p1.lobby_connection.launch_game.called assert p2.lobby_connection.launch_game.called
async def test_start_game(ladder_service: LadderService, game_service: GameService, player_factory): p1 = player_factory('Dostya', player_id=1, with_lobby_connection=True) p2 = player_factory('Rhiza', player_id=2, with_lobby_connection=True) game_service.ladder_maps = [(1, 'scmp_007', 'maps/scmp_007.zip')] with mock.patch('server.games.game.Game.await_hosted', CoroutineMock()): await ladder_service.start_game(p1, p2) assert p1.lobby_connection.launch_game.called assert p2.lobby_connection.launch_game.called
async def test_start_game_timeout(ladder_service: LadderService, game_service: GameService, player_factory): p1 = player_factory('Dostya', player_id=1, with_lobby_connection=True) p2 = player_factory('Rhiza', player_id=2, with_lobby_connection=True) game_service.ladder_maps = [(1, 'scmp_007', 'maps/scmp_007.zip')] await ladder_service.start_game(p1, p2) p1.lobby_connection.send.assert_called_once_with( {"command": "game_launch_cancelled"}) p2.lobby_connection.send.assert_called_once_with( {"command": "game_launch_cancelled"}) assert p1.lobby_connection.launch_game.called # TODO: Once client supports `game_launch_cancelled` change this to `assert not ...` assert p2.lobby_connection.launch_game.called
async def test_start_game_timeout(ladder_service: LadderService, game_service: GameService): p1 = mock.create_autospec(Player('Dostya', id=1)) p2 = mock.create_autospec(Player('Rhiza', id=2)) p1.id = 1 p2.id = 2 game_service.ladder_maps = [(1, 'scmp_007', 'maps/scmp_007.zip')] with mock.patch('server.games.game.Game.sleep', CoroMock()): await ladder_service.start_game(p1, p2) p1.lobby_connection.send.assert_called_once_with( {"command": "game_launch_timeout"}) p2.lobby_connection.send.assert_called_once_with( {"command": "game_launch_timeout"}) assert p1.lobby_connection.launch_game.called # TODO: Once client supports `game_launch_timeout` change this to `assert not ...` assert p2.lobby_connection.launch_game.called
def mock_games(mock_players): return mock.create_autospec(GameService(mock_players))
def mock_games(mock_players): from server import GameService return mock.create_autospec(GameService(mock_players))
def game_service(loop, player_service, game_stats_service): from server import GameService return GameService(player_service, game_stats_service)