async def test_handle_action_GameResult_calls_add_result(
        game: Game, game_connection: GameConnection):
    game_connection.connect_to_host = CoroutineMock()

    await game_connection.handle_action('GameResult', [0, 'score -5'])
    game.add_result.assert_called_once_with(game_connection.player.id, 0,
                                            'score', -5)
Esempio n. 2
0
async def test_handle_action_GameResult_draw_ends_sim(
        game: Game, game_connection: GameConnection):
    game_connection.connect_to_host = CoroMock()
    await game_connection.handle_action('GameResult', [0, 'draw'])

    assert game_connection.finished_sim
    assert game.check_sim_end.called
async def test_handle_action_GameState_lobby_calls_ConnectToHost(
        game: Game, game_connection: GameConnection, event_loop, players):
    game_connection.send = CoroutineMock()
    game_connection.connect_to_host = CoroutineMock()
    game_connection.player = players.joining
    players.joining.game = game
    game.host = players.hosting
    game.map_file_path = 'maps/some_map.zip'
    game.map_folder_name = 'some_map'

    await game_connection.handle_action('GameState', ['Lobby'])
    await exhaust_callbacks(event_loop)

    game_connection.connect_to_host.assert_called_with(
        players.hosting.game_connection)
async def test_handle_lobby_state_handles_GameError(
        real_game: Game, game_connection: GameConnection, event_loop, players):
    game_connection.abort = CoroutineMock()
    game_connection.connect_to_host = CoroutineMock()
    game_connection.player = players.joining
    game_connection.game = real_game

    players.joining.game = real_game

    real_game.host = players.hosting
    real_game.state = GameState.ENDED

    await game_connection.handle_action('GameState', ['Lobby'])
    await exhaust_callbacks(event_loop)

    game_connection.abort.assert_called_once()
Esempio n. 5
0
async def test_handle_action_GameState_lobby_calls_ConnectToHost(
        game: Game, game_connection: GameConnection, players):
    game_connection.send_message = mock.MagicMock()
    game_connection.connect_to_host = CoroMock()
    game_connection.player = players.joining
    players.joining.game = game
    game.host = players.hosting
    game.map_file_path = 'maps/some_map.zip'
    game.map_folder_name = 'some_map'

    await game_connection.handle_action('GameState', ['Lobby'])
    # Give the connection coro time to run
    await asyncio.sleep(0.1)

    game_connection.connect_to_host.assert_called_with(
        players.hosting.game_connection)
Esempio n. 6
0
async def test_handle_action_GameState_lobby_calls_ConnectToPeer(
        game: Game, game_connection: GameConnection, event_loop, players):
    game_connection.send = CoroutineMock()
    game_connection.connect_to_host = CoroutineMock()
    game_connection.connect_to_peer = CoroutineMock()
    game_connection.player = players.joining

    players.joining.game = game

    game.host = players.hosting
    game.map_file_path = "maps/some_map.zip"
    game.map_folder_name = "some_map"
    peer_conn = mock.Mock()
    players.peer.game_connection = peer_conn
    game.connections = [peer_conn]

    await game_connection.handle_action("GameState", ["Lobby"])
    await exhaust_callbacks(event_loop)

    game_connection.connect_to_peer.assert_called_with(peer_conn)