Пример #1
0
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.send = CoroutineMock()
    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.send.assert_any_call({
        "command": "notice",
        "style": "info",
        "text": "The game you were connected to is no longer available"
    })
Пример #2
0
async def test_command_avatar_list(mocker, lobbyconnection: LobbyConnection):
    lobbyconnection.send = CoroutineMock()
    lobbyconnection.player.id = 2  # Dostya test user

    await lobbyconnection.on_message_received({
        "command": "avatar",
        "action": "list_avatar"
    })

    lobbyconnection.send.assert_any_call({
        "command": "avatar",
        "avatarlist": [{"url": "https://content.faforever.com/faf/avatars/qai2.png", "tooltip": "QAI"}, {"url": "https://content.faforever.com/faf/avatars/UEF.png", "tooltip": "UEF"}]
    })
Пример #3
0
async def test_game_connection_not_restored_if_no_such_game_exists(lobbyconnection: LobbyConnection, mocker):
    del lobbyconnection.player.game_connection
    lobbyconnection.send = CoroutineMock()
    lobbyconnection.player.state = PlayerState.IDLE
    await lobbyconnection.on_message_received({
        "command": "restore_game_session",
        "game_id": 123
    })

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

    lobbyconnection.send.assert_any_call({
        "command": "notice",
        "style": "info",
        "text": "The game you were connected to does no longer exist"
    })
Пример #4
0
async def test_command_ice_servers(lobbyconnection: LobbyConnection,
                                   mock_nts_client):
    lobbyconnection.send = CoroutineMock()
    lobbyconnection.coturn_generator.server_tokens = Mock(
        return_value=["coturn_tokens"])
    mock_nts_client.server_tokens.return_value = ["twilio_tokens"]

    await lobbyconnection.on_message_received({"command": "ice_servers"})

    mock_nts_client.server_tokens.assert_called_once()
    lobbyconnection.send.assert_called_once_with({
        "command":
        "ice_servers",
        "ice_servers": ["coturn_tokens", "twilio_tokens"],
        "ttl":
        config.TWILIO_TTL
    })