예제 #1
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"
    })
예제 #2
0
def lobbyconnection(
    event_loop,
    database,
    mock_protocol,
    mock_games,
    mock_players,
    mock_player,
    mock_geoip,
    mock_nts_client
):
    lc = LobbyConnection(
        database=database,
        geoip=mock_geoip,
        game_service=mock_games,
        players=mock_players,
        nts_client=mock_nts_client,
        ladder_service=asynctest.create_autospec(LadderService)
    )

    lc.player = mock_player
    lc.protocol = mock_protocol
    lc.player_service.fetch_player_data = CoroutineMock()
    lc.peer_address = Address("127.0.0.1", 1234)
    lc._authenticated = True
    return lc
예제 #3
0
def lobbyconnection(loop, mock_context, mock_protocol, mock_games, mock_players, mock_player):
    lc = LobbyConnection(loop,
                         context=mock_context,
                         games=mock_games,
                         players=mock_players)
    lc.player = mock_player
    lc.connectivity = mock.create_autospec(Connectivity)
    lc.protocol = mock_protocol
    return lc
예제 #4
0
def lobbyconnection(loop, mock_context, mock_protocol, mock_games, mock_players, mock_player):
    lc = LobbyConnection(loop,
                         context=mock_context,
                         games=mock_games,
                         players=mock_players)
    lc.player = mock_player
    lc.connectivity = mock.create_autospec(Connectivity)
    lc.protocol = mock_protocol
    return lc
예제 #5
0
async def test_command_avatar_list(mocker, lobbyconnection: LobbyConnection, mock_player: Player):
    protocol = mocker.patch.object(lobbyconnection, 'protocol')
    lobbyconnection.player = mock_player
    lobbyconnection.player.id = 2  # Dostya test user

    await lobbyconnection.command_avatar({
        'action': 'list_avatar'
    })

    protocol.send_message.assert_any_call({
        "command": "avatar",
        "avatarlist": [{'url': 'http://content.faforever.com/faf/avatars/qai2.png', 'tooltip': 'QAI'}]
    })
예제 #6
0
async def test_command_avatar_list(mocker, lobbyconnection: LobbyConnection, mock_player: Player):
    protocol = mocker.patch.object(lobbyconnection, 'protocol')
    lobbyconnection.player = mock_player
    lobbyconnection.player.id = 2  # Dostya test user

    await lobbyconnection.command_avatar({
        'action': 'list_avatar'
    })

    protocol.send_message.assert_any_call({
        "command": "avatar",
        "avatarlist": [{'url': 'http://content.faforever.com/faf/avatars/qai2.png', 'tooltip': 'QAI'}]
    })
예제 #7
0
async def test_command_avatar_select(mocker, lobbyconnection: LobbyConnection, mock_player: Player):
    lobbyconnection.player = mock_player
    lobbyconnection.player.id = 2  # Dostya test user

    await lobbyconnection.command_avatar({
        'action': 'select',
        'avatar': "http://content.faforever.com/faf/avatars/qai2.png"
    })

    async with db.db_pool.get() as conn:
        cursor = await conn.cursor()
        await cursor.execute("SELECT selected from avatars where idUser=2")
        result = await cursor.fetchone()
        assert result == (1,)
예제 #8
0
def lobbyconnection(loop, mock_protocol, mock_games, mock_players, mock_player,
                    mock_geoip):
    lc = LobbyConnection(geoip=mock_geoip,
                         games=mock_games,
                         players=mock_players,
                         nts_client=mock_nts_client,
                         ladder_service=mock.create_autospec(LadderService))

    lc.player = mock_player
    lc.protocol = mock_protocol
    lc.player_service.get_permission_group.return_value = 0
    lc.player_service.fetch_player_data = CoroMock()
    lc.peer_address = Address('127.0.0.1', 1234)
    return lc
예제 #9
0
async def test_command_avatar_select(mocker, lobbyconnection: LobbyConnection, mock_player: Player):
    lobbyconnection.player = mock_player
    lobbyconnection.player.id = 2  # Dostya test user

    await lobbyconnection.command_avatar({
        'action': 'select',
        'avatar': "http://content.faforever.com/faf/avatars/qai2.png"
    })

    async with db.db_pool.get() as conn:
        cursor = await conn.cursor()
        await cursor.execute("SELECT selected from avatars where idUser=2")
        result = await cursor.fetchone()
        assert result == (1,)
예제 #10
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
예제 #11
0
async def test_game_connection_not_restored_if_no_such_game_exists(
        lobbyconnection: LobbyConnection, mocker, mock_player):
    protocol = mocker.patch.object(lobbyconnection, 'protocol')
    lobbyconnection.player = mock_player
    lobbyconnection.player.game_connection = None
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.command_restore_game_session({'game_id': 123})

    assert not lobbyconnection.player.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 does no longer exist"
    })
예제 #12
0
async def test_command_avatar_select(mocker, db_engine,
                                     lobbyconnection: LobbyConnection,
                                     mock_player: Player):
    lobbyconnection.player = mock_player
    lobbyconnection.player.id = 2  # Dostya test user
    lobbyconnection._authenticated = True

    await lobbyconnection.on_message_received({
        'command':
        'avatar',
        'action':
        'select',
        'avatar':
        "http://content.faforever.com/faf/avatars/qai2.png"
    })

    async with db_engine.acquire() as conn:
        result = await conn.execute(
            "SELECT selected from avatars where idUser=2")
        row = await result.fetchone()
        assert row[0] == 1