Ejemplo n.º 1
0
def test_create_lol_user(discord_id, riot_puuid):
    """
    Tests that creating a new LoLUser works correctly
    """
    queried_users = session.query(LoLUser).all()
    if len(queried_users) > 0:
        session.query(LoLUser).delete()
        session.commit()

    assert len(session.query(LoLUser).all()) == 0

    user = LoLUser(discord_id, riot_puuid, winrate=True)
    session.add(user)
    session.commit()

    queried_users = session.query(LoLUser).all()

    assert len(queried_users) == 1

    queried_user = queried_users[0]
    assert queried_user.discord_id == discord_id
    assert queried_user.riot_puuid == riot_puuid
    assert queried_user.last_updated > 0
    assert queried_user.winrate
    assert queried_user.wins == 0
    assert queried_user.losses == 0
Ejemplo n.º 2
0
        def wrapper(mock_send_discord_message, ):
            user = LoLUser(mock_discord_id(), "useless")

            trolled = TrolledRule
            trolled.obj.run({"hard_inted": False, "inted": False}, user)

            func(mock_send_discord_message)
Ejemplo n.º 3
0
        def wrapper(mock_get_stat):

            match_data = get_mock_match_data()
            match_timeline = get_mock_match_timeline()

            set_lol_data_context(
                match_data, match_timeline, get_mock_match_data_account_id()
            )
            reset_statistics()

            stat_table = {
                "kills": {
                    "solo_kills": solo_kills,
                    "total_kills": 0,
                    "data": {},
                },
                "deaths": {
                    "solo_deaths": solo_deaths,
                    "total_deaths": 15,
                    "data": {0: 0, 1: 0},
                    "has_max_deaths": True,
                    "max_deaths_to_champ": {"champ_id": 1, "deaths": 0},
                },
                "champions": {1: "MasterLi", 0: "AnotherBitch"},
                "winner": {"user": win, "team": 100},
            }

            mock_get_stat.side_effect = lambda x: stat_table[x]

            user = LoLUser(mock_discord_id(), "useless")

            inted = IntedRule
            response = inted.obj.should_run({"hard_inted": hard_inted}, user)

            func(response)
Ejemplo n.º 4
0
def set_lol_user_winrate(user: LoLUser, value: bool):
    """
    Sets winrate tracking for a given user

    Args:
        user (LoLUser): the user to enable winrate tracking for
        value (bool): True if winrate should be enabled, false otherwise
    """
    user.winrate = value
    session.commit()
Ejemplo n.º 5
0
def update_lol_user_last_updated(user: LoLUser, timestamp: int):
    """
    Updates a users last updated time

    Args:
        user (LoLuser): the user to update
        timestamp (int): the time in unix ms that the user
            was updated at
    """
    user.last_updated = timestamp
    session.commit()
Ejemplo n.º 6
0
def create_new_lol_user(discord_id: int, riot_puuid: str):
    """
    Creates a new lol user with the given discord id and riot puuid

    Args:
        discord_id (int): the id of the discord user
        riot_puuid (str): the id of the riot account
    """
    user = LoLUser(discord_id, riot_puuid)
    session.add(user)
    session.commit()
Ejemplo n.º 7
0
def should_run_ge(user: LoLUser = LoLUser(1, "P1", True)):
    """"""
    def decorator(func):
        """"""
        def wrapper():
            winrate = WinrateGERule
            response = winrate.obj.should_run({}, user)

            func(response)

        return wrapper

    return decorator
Ejemplo n.º 8
0
        def wrapper(
            mock_get_stat,
            mock_send_discord_message,
            mock_get_lol_text_by_group,
        ):

            match_data = get_mock_match_data()
            match_timeline = get_mock_match_timeline()

            set_lol_data_context(
                match_data, match_timeline, get_mock_match_data_account_id()
            )
            reset_statistics()

            stat_table = {
                "kills": {
                    "solo_kills": solo_kills,
                    "total_kills": 0,
                    "data": {},
                },
                "participant_ids": {
                    get_mock_match_data_account_id(): 1,
                    "user": 1,
                },
                "deaths": {
                    "solo_deaths": solo_deaths,
                    "total_deaths": 15,
                    "data": {0: 0, 1: 0},
                    "has_max_deaths": True,
                    "max_deaths_to_champ": {"champ_id": 1, "deaths": 0},
                },
                "champions": {1: "MasterLi", 0: "AnotherBitch"},
                "winner": {"user": False, "team": 100},
            }

            mock_get_stat.side_effect = lambda x: stat_table[x]

            user = LoLUser(mock_discord_id(), "useless")

            text_table = {
                "p0": [LoLText("p", "prefix", 1234)],
                "sp0": [LoLText("sp", "stat_prefix", 1234)],
                "s0": [LoLText("s", "suffix", 1234)],
            }

            mock_get_lol_text_by_group.side_effect = lambda x: text_table[x]

            inted = IntedRule
            inted.obj.run({"hard_inted": False}, user)

            func(mock_send_discord_message)
Ejemplo n.º 9
0
        def wrapper(mock_get_stat, mock_send_discord_message):

            match_data = get_mock_match_data()
            match_timeline = get_mock_match_timeline()

            set_lol_data_context(match_data, match_timeline,
                                 get_mock_match_data_account_id())
            reset_statistics()

            stat_table = {
                "kills": {
                    "solo_kills": 0,
                    "total_kills": 0,
                    "data": {}
                },
                "deaths": {
                    "solo_deaths": solo_deaths,
                    "total_deaths": 15,
                    "data": {
                        0: 0,
                        1: single_champ_solo_deaths
                    },
                    "has_max_deaths": True,
                    "max_deaths_to_champ": {
                        "champ_id": 1,
                        "deaths": single_champ_solo_deaths,
                    },
                },
                "champions": {
                    1: "MasterLi",
                    0: "AnotherBitch"
                },
                "winner": {
                    "user": False,
                    "team": 100
                },
            }

            mock_get_stat.side_effect = lambda x: stat_table[x]

            user = LoLUser(mock_discord_id(), "useless")

            hard_inted = HardIntedRule
            hard_inted.obj.run({}, user)

            func(mock_send_discord_message)
Ejemplo n.º 10
0
def test_delete_lol_user(discord_id, riot_puuid):
    """
    Tests that a LoLUser can be deleted
    """
    queried_users = session.query(LoLUser).all()
    user = None
    if len(queried_users) != 1:
        # user is not present, insert new user
        user = LoLUser(discord_id, riot_puuid)
        session.add(user)
        session.commit()
    else:
        user = queried_users[0]

    session.query(LoLUser).filter(LoLUser.discord_id == discord_id).delete()
    session.commit()

    assert len(session.query(LoLUser).all()) == 0
Ejemplo n.º 11
0
def run_eod(users: List[LoLUser] = [LoLUser(1, "p1", True, 1, 1)]):
    def decorator(func):
        @mock.patch.object(
            discord_ritoman.lol.rules.winrate_eod,
            "get_lol_users_with_winrate_enabled",
        )
        @mock.patch.object(
            discord_ritoman.lol.rules.winrate_eod, "send_discord_message"
        )
        def wrapper(
            mock_send_discord_message, mock_get_lol_users_with_winrate_enabled
        ):
            mock_get_lol_users_with_winrate_enabled.return_value = users
            winrate = WinrateEODRule
            winrate.obj.run({})
            func(mock_send_discord_message, users)

        return wrapper

    return decorator
Ejemplo n.º 12
0
def run_ge(user: LoLUser = LoLUser(1, "P1", True, 1, 1),
           game_result: bool = True):
    """"""
    def decorator(func):
        """"""
        @mock.patch.object(discord_ritoman.lol.rules.winrate_ge, "get_stat")
        @mock.patch.object(discord_ritoman.lol.rules.winrate_ge,
                           "update_lol_user_winrate")
        def wrapper(mock_update_lol_user_winrate, mock_get_stat):
            stat_table = {"winner": {"user": game_result}}

            mock_get_stat.side_effect = lambda x: stat_table[x]

            winrate = WinrateGERule
            winrate.obj.run({}, user)

            func(mock_update_lol_user_winrate, user)

        return wrapper

    return decorator
Ejemplo n.º 13
0
def run_poll_lol_api(
    users: List[LoLUser] = [LoLUser(1, "p1")],
    with_logging_calls: Dict[Any, Any] = {},
):
    def decorator(func):
        @mock.patch.object(discord_ritoman.api, "run_end_of_game")
        @mock.patch.object(discord_ritoman.api, "with_logging")
        @mock.patch.object(discord_ritoman.api, "get_all_lol_users")
        def wrapper(mock_get_all_lol_users, mock_with_logging,
                    mock_run_end_of_game):
            def with_logging_handler(func, logger, log_message, default,
                                     **kwargs):
                # validate other parameters here (if wanted)
                return with_logging_calls[func]

            mock_get_all_lol_users.return_value = users
            mock_with_logging.side_effect = with_logging_handler

            poll_lol_api()
            func(mock_run_end_of_game, users)

        return wrapper

    return decorator
Ejemplo n.º 14
0
def mock_users() -> List[LoLUser]:
    """
    returns all mock users used by this module
    """
    return [LoLUser(1, "r1"), LoLUser(2, "r2", True), LoLUser(3, "r3", True)]
Ejemplo n.º 15
0
    assert len(users) == 0
    mock_send_discord_message.assert_any_call(
        "Well f**k you little shits didn't play a single game. how sad."
    )


@run_eod()
def test_run_eq(mock_send_discord_message, users):
    """"""
    for user in users:
        mock_send_discord_message.assert_any_call(
            f"<@{user.discord_id}> f*****g wasted their time today with {user.wins} wins and {user.losses} losses"
        )


@run_eod(users=[LoLUser(1, "p1", True, 1, 2)])
def test_run_loss_gt_win(mock_send_discord_message, users):
    """"""
    for user in users:
        mock_send_discord_message.assert_any_call(
            f"<@{user.discord_id}> inted today with {user.wins} wins and {user.losses} losses. you f****d up, but im sure it was your team who trolled and not your fault"
        )


@run_eod(users=[LoLUser(1, "p1", True, 2, 1)])
def test_run_loss_lt_win(mock_send_discord_message, users):
    """"""
    for user in users:
        mock_send_discord_message.assert_any_call(
            f"<@{user.discord_id}> carried today with {user.wins} wins and {user.losses} losses, good job summoner"
        )
Ejemplo n.º 16
0
            winrate.obj.run({}, user)

            func(mock_update_lol_user_winrate, user)

        return wrapper

    return decorator


@should_run_ge()
def test_should_run(response):
    """"""
    assert response


@should_run_ge(user=LoLUser(1, "P1", False))
def test_should_run_not_enabled(response):
    """"""
    assert not response


@run_ge()
def test_run(mock_update_lol_user_winrate, user):
    """"""
    mock_update_lol_user_winrate.assert_called_once_with(user, GameResult.WIN)


@run_ge(game_result=False)
def test_run_loss(mock_update_lol_user_winrate, user):
    """"""
    mock_update_lol_user_winrate.assert_called_once_with(user, GameResult.LOSS)