async def test_game_connection_not_restored_if_game_state_prohibits(
        lobbyconnection: LobbyConnection, game_service: GameService,
        game_stats_service, game_state, mocker, database):
    del lobbyconnection.player.game_connection
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(
        Game(42, database, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = 'faf'
    game.id = 42
    game_service._games[42] = game

    await lobbyconnection.on_message_received({
        'command': 'restore_game_session',
        'game_id': 42
    })

    assert not lobbyconnection.game_connection
    assert lobbyconnection.player.state == PlayerState.IDLE

    lobbyconnection.protocol.send_message.assert_any_call({
        "command":
        "notice",
        "style":
        "info",
        "text":
        "The game you were connected to is no longer available"
    })
Пример #2
0
async def test_game_connection_restored_if_game_exists(
    lobbyconnection: LobbyConnection,
    game_service: GameService,
    game_stats_service,
    game_state,
    database
):
    del lobbyconnection.player.game_connection
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(Game(42, database, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = "faf"
    game.id = 42
    game_service._games[42] = game

    await lobbyconnection.on_message_received({
        "command": "restore_game_session",
        "game_id": 42
    })

    assert lobbyconnection.game_connection
    assert lobbyconnection.player.state is PlayerState.PLAYING
    assert lobbyconnection.player.game is game
Пример #3
0
async def test_game_connection_not_restored_if_game_state_prohibits(
        lobbyconnection: LobbyConnection, game_service: GameService,
        game_stats_service, game_state, mock_player, mocker):
    protocol = mocker.patch.object(lobbyconnection, 'protocol')
    lobbyconnection.player = mock_player
    lobbyconnection.player.game_connection = None
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(Game(42, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = 'faf'
    game.id = 42
    game_service.games[42] = game

    lobbyconnection.command_restore_game_session({'game_id': 42})

    assert not lobbyconnection.game_connection
    assert lobbyconnection.player.state == PlayerState.IDLE

    protocol.send_message.assert_any_call({
        "command":
        "notice",
        "style":
        "info",
        "text":
        "The game you were connected to is no longer available"
    })
Пример #4
0
async def test_game_connection_restored_if_game_exists(
        lobbyconnection: LobbyConnection, game_service: GameService,
        game_stats_service, game_state, mock_player):
    lobbyconnection.player = mock_player
    lobbyconnection.player.game_connection = None
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(Game(42, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = 'faf'
    game.id = 42
    game_service.games[42] = game

    lobbyconnection.command_restore_game_session({'game_id': 42})

    assert lobbyconnection.game_connection
    assert lobbyconnection.player.state == PlayerState.PLAYING