Exemple #1
0
def test_abort(game_connection: GameConnection, game: Game, players):
    game_connection.player = players.hosting
    game_connection.game = game

    game_connection.abort()

    game.remove_game_connection.assert_called_with(game_connection)
async def test_handle_action_invalid(game_connection: GameConnection):
    game_connection.abort = CoroutineMock()

    await game_connection.handle_action('ThisDoesntExist', [1, 2, 3])

    game_connection.abort.assert_not_called()
    game_connection.protocol.send_message.assert_not_called()
async def test_handle_action_TeamkillHappened_AI(
        game: Game, game_connection: GameConnection, database):
    # Should fail with a sql constraint error if this isn't handled correctly
    game_connection.abort = CoroutineMock()
    await game_connection.handle_action('TeamkillHappened',
                                        ['200', 0, 'Dostya', '0', 'Rhiza'])
    game_connection.abort.assert_not_called()
async def test_handle_action_TeamkillHappened_AI(
        game: Game, game_connection: GameConnection, database):
    # Should fail with a sql constraint error if this isn't handled correctly
    game_connection.abort = CoroutineMock()
    await game_connection.handle_action("TeamkillHappened",
                                        ["200", 0, "Dostya", "0", "Rhiza"])
    game_connection.abort.assert_not_called()
async def test_handle_action_GameState_idle_non_searching_player_aborts(game_connection: GameConnection, players):
    game_connection.player = players.hosting
    game_connection.lobby = mock.Mock()
    game_connection.abort = mock.Mock()
    players.hosting.state = PlayerState.IDLE

    await game_connection.handle_action('GameState', ['Idle'])

    game_connection.abort.assert_any_call()
Exemple #6
0
async def test_handle_action_GameState_idle_non_searching_player_aborts(
        game_connection: GameConnection, players):
    game_connection.player = players.hosting
    game_connection.lobby = mock.Mock()
    game_connection.abort = mock.Mock()
    players.hosting.state = PlayerState.IDLE

    await game_connection.handle_action('GameState', ['Idle'])

    game_connection.abort.assert_any_call()
async def test_handle_action_GameState_lobby_calls_abort(
        game: Game, game_connection: GameConnection, event_loop, players):
    game_connection.send = CoroutineMock()
    game_connection.abort = CoroutineMock()
    game_connection.player = players.joining
    players.joining.game = game
    game.host = players.hosting
    game.host.state = PlayerState.IDLE
    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.abort.assert_called_once()
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()