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 create_bet(
    player: int, better: int, bet: int, prediction: bool, created: int
):
    """
    creates a new bet on a player
    """
    bet = LoLBets(player, better, bet, prediction, created)
    session.add(bet)
    session.commit()
Ejemplo n.º 3
0
def add_lol_game(user: LoLUser, game_id: int, start_time: int, game_mode: str):
    """
    Adds an active lol game to the db
    """
    active_game = LoLActiveGames(
        game_id, user.discord_id, start_time, game_mode
    )
    session.add(active_game)
    session.commit()
Ejemplo n.º 4
0
def test_create_lol_text(lol_text_group_name, lol_user):
    """
    Tests that a lol text can be created successfully
    """
    assert len(session.query(LoLText).all()) == 0

    text = LoLText(lol_text_group_name, "ending.", lol_user)
    session.add(text)
    session.commit()

    assert len(session.query(LoLText).all()) == 1
Ejemplo n.º 5
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.º 6
0
def add_lol_text(group_name: str, content: str, user_id: int):
    """
    Adds a new text to the db

    Args:
        group_name (str): the name of the group being added (must be unique)
        content (str): the text to be displayed
        user_id (int): the discord id of the user adding the group
    """
    text = LoLText(group_name, content, user_id)
    session.add(text)
    session.commit()
Ejemplo n.º 7
0
def add_lol_text_group(group_name: str, group_description: str, user_id: int):
    """
    Adds a new text group with a description to the db

    Args:
        group_name (str): the name of the group being added (must be unique)
        group_description (str): a description of what this group is used for
        user_id (int): the discord id of the user adding the group
    """
    group = LoLTextGroup(group_name, group_description, user_id)
    session.add(group)
    session.commit()
Ejemplo n.º 8
0
def test_create_lol_text_group(lol_text_group_name, lol_text_group_usage,
                               lol_user):
    """
    Tests that a lol text group can be created successfully
    """
    assert len(session.query(LoLTextGroup).all()) == 0

    text_group = LoLTextGroup(lol_text_group_name, lol_text_group_usage,
                              lol_user)
    session.add(text_group)
    session.commit()

    assert len(session.query(LoLTextGroup).all()) == 1
Ejemplo n.º 9
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.º 10
0
def test_delete_lol_text_group(lol_text_group_name, lol_text_group_usage,
                               lol_user):
    """
    Tests that a lol text group can be deleted successfully
    """
    queried_groups = session.query(LoLTextGroup).all()
    group = None
    if len(queried_groups) != 1:
        group = LoLTextGroup(lol_text_group_name, lol_text_group_usage,
                             lol_user)
        session.add(group)
        session.commit()
    else:
        group = queried_groups[0]

    session.query(LoLTextGroup).filter(
        LoLTextGroup.name == lol_text_group_name).delete()
    session.commit()

    assert len(session.query(LoLTextGroup).all()) == 0
Ejemplo n.º 11
0
def setup_module(module):
    """ setup any state specific to the execution of the given module."""
    # clean db before insertions
    session.query(LoLUser).delete()
    session.commit()

    session.query(LoLText).delete()
    session.commit()

    session.query(LoLTextGroup).delete()
    session.commit()

    # populate db with mock users to test with
    users = mock_users()
    for user in users:
        session.add(user)
        session.commit()

    text_groups = mock_text_groups()
    for text_group in text_groups:
        session.add(text_group)
        session.commit()

    texts = mock_text(text_groups[0], text_groups[1])
    for text in texts:
        session.add(text)
        session.commit()