Exemple #1
0
def test_game_session_admin_player_move(clean_database, flask_app,
                                        mock_emit_session_update, offset: int):
    user1 = database.User.create(id=1234, name="The Name")
    session = database.GameSession.create(id=1,
                                          name="Debug",
                                          state=GameSessionState.IN_PROGRESS,
                                          creator=user1)
    database.GameSessionPreset.create(session=session, row=0, preset="{}")
    database.GameSessionPreset.create(session=session, row=1, preset="{}")
    database.GameSessionPreset.create(session=session, row=2, preset="{}")
    database.GameSessionMembership.create(user=user1,
                                          session=session,
                                          row=1,
                                          admin=False)
    sio = MagicMock()
    sio.get_current_user.return_value = user1

    # Run
    with flask_app.test_request_context():
        game_session.game_session_admin_player(sio, 1, 1234, "move", offset)

    # Assert
    membership = database.GameSessionMembership.get(user=user1,
                                                    session=session)
    assert membership.row == 1 + offset
    mock_emit_session_update.assert_called_once_with(
        database.GameSession.get(id=1))
Exemple #2
0
def test_game_session_admin_player_switch_is_observer(clean_database,
                                                      flask_app,
                                                      mock_emit_session_update,
                                                      is_observer):
    user1 = database.User.create(id=1234, name="The Name")
    session = database.GameSession.create(id=1,
                                          name="Debug",
                                          state=GameSessionState.IN_PROGRESS,
                                          creator=user1)
    database.GameSessionPreset.create(session=session, row=0, preset="{}")
    database.GameSessionMembership.create(user=user1,
                                          session=session,
                                          row=None if is_observer else 0,
                                          admin=False)
    sio = MagicMock()
    sio.get_current_user.return_value = user1

    # Run
    with flask_app.test_request_context():
        game_session.game_session_admin_player(
            sio, 1, 1234, SessionAdminUserAction.SWITCH_IS_OBSERVER.value,
            None)

    # Assert
    membership = database.GameSessionMembership.get(user=user1,
                                                    session=session)
    assert membership.is_observer != is_observer
    if is_observer:
        assert membership.row == 0
    mock_emit_session_update.assert_called_once_with(
        database.GameSession.get(id=1))
Exemple #3
0
def test_game_session_admin_kick_last(clean_database, flask_app, mocker):
    mock_emit = mocker.patch("flask_socketio.emit")

    user = database.User.create(id=1234, discord_id=5678, name="The Name")
    sio = MagicMock()
    sio.get_current_user.return_value = user
    game_session.create_game_session(sio, "My Room")
    session = database.GameSession.get_by_id(1)
    database.GameSessionTeamAction.create(session=session, provider_row=0, provider_location_index=0, receiver_row=0,
                                          time=datetime.datetime(2020, 5, 2, 10, 20, tzinfo=datetime.timezone.utc))

    # Run
    with flask_app.test_request_context():
        game_session.game_session_admin_player(sio, 1, 1234, SessionAdminUserAction.KICK.value, None)

    # Assert
    for table in [database.GameSession, database.GameSessionPreset,
                  database.GameSessionMembership, database.GameSessionTeamAction]:
        assert list(table.select()) == []
    assert database.User.get_by_id(1234) == user

    mock_emit.assert_called_once_with(
        'game_session_update',
        {'id': 1, 'name': 'My Room', 'state': 'setup', 'players': [], 'presets': [], 'actions': [],
         'spoiler': None, 'word_hash': None, 'seed_hash': None, 'permalink': None, 'generation_in_progress': None},
        room='game-session-1')
Exemple #4
0
def test_game_session_admin_player_include_in_session(clean_database, flask_app, mock_emit_session_update):
    users = [
        database.User.create(id=1234 + 1000 * i, name=f"The {i}")
        for i in range(4)
    ]
    session = database.GameSession.create(id=1, name="Debug", state=GameSessionState.IN_PROGRESS, creator=users[0])
    for i in range(4):
        database.GameSessionPreset.create(session=session, row=i, preset="{}")

    database.GameSessionMembership.create(user=users[0], session=session, row=0, admin=True)
    database.GameSessionMembership.create(user=users[1], session=session, row=2, admin=False)
    database.GameSessionMembership.create(user=users[2], session=session, row=1, admin=False)
    database.GameSessionMembership.create(user=users[3], session=session, row=None, admin=False)
    sio = MagicMock()
    sio.get_current_user.return_value = users[0]

    # Run
    with flask_app.test_request_context():
        game_session.game_session_admin_player(sio, 1, 4234, SessionAdminUserAction.SWITCH_IS_OBSERVER.value, None)

    # Assert
    membership = database.GameSessionMembership.get(user=users[3], session=session)
    assert not membership.is_observer
    assert membership.row == 3
    mock_emit_session_update.assert_called_once_with(database.GameSession.get(id=1))
Exemple #5
0
def test_game_session_admin_player_patcher_file(mock_layout_description: PropertyMock,
                                                mock_create_patcher_file: MagicMock,
                                                flask_app,
                                                clean_database):
    user1 = database.User.create(id=1234, name="The Name")
    user2 = database.User.create(id=1235, name="Brother")
    session = database.GameSession.create(id=1, name="Debug", state=GameSessionState.IN_PROGRESS, creator=user1)
    database.GameSessionPreset.create(session=session, row=0, preset="{}")
    database.GameSessionPreset.create(session=session, row=1, preset="{}")
    database.GameSessionPreset.create(session=session, row=2, preset="{}")
    database.GameSessionMembership.create(user=user1, session=session, row=2, admin=False)
    database.GameSessionMembership.create(user=user2, session=session, row=1, admin=False)
    sio = MagicMock()
    sio.get_current_user.return_value = user1

    cosmetic = CosmeticPatches(open_map=False)

    # Run
    with flask_app.test_request_context():
        result = game_session.game_session_admin_player(sio, 1, 1234, "create_patcher_file", cosmetic.as_json)

    # Assert
    mock_create_patcher_file.assert_called_once_with(
        mock_layout_description.return_value,
        PlayersConfiguration(2, {
            0: "Player 1",
            1: "Brother",
            2: "The Name",
        }),
        cosmetic
    )
    assert result is mock_create_patcher_file.return_value