Exemplo n.º 1
0
def test_on_ready(gid, obj_guild):
    # New guild test
    DataConnector.run_query("DELETE FROM {}.guilds WHERE guild_id='{}'".format(
        SCHEMA_NAME, gid))
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 0

    lst_guilds = []
    lst_guilds.append(obj_guild)

    DataProcessor._on_ready(lst_guilds)
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1

    # Same guild list test
    DataProcessor._on_ready(lst_guilds)
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1

    # Additional guild test
    new_gid = '54321'
    DataConnector.run_query("DELETE FROM {}.guilds WHERE guild_id='{}'".format(
        SCHEMA_NAME, new_gid))
    new_obj_guild = guilds(new_gid)
    lst_guilds.append(new_obj_guild)
    DataProcessor._on_ready(lst_guilds)
    df = DataConnector.read_data("""SELECT *
                                    FROM {}.guilds
                                    WHERE guild_id='{}' or guild_id='{}'
                                 """.format(SCHEMA_NAME, gid, new_gid))
    assert df.shape[0] == 2

    # Removed guilds test
    empty_lst_guilds = []
    DataProcessor._on_ready(empty_lst_guilds)
    df = DataConnector.read_data("""SELECT *
                                    FROM {}.guilds
                                    WHERE guild_id='{}' or guild_id='{}'
                                 """.format(SCHEMA_NAME, gid, new_gid))
    assert df.shape[0] == 0

    # One last sanity check
    lst_guilds.remove(new_obj_guild)
    DataProcessor._on_ready(lst_guilds)
    df = DataConnector.read_data("""SELECT *
                                    FROM {}.guilds
                                    WHERE guild_id='{}' or guild_id='{}'
                                 """.format(SCHEMA_NAME, gid, new_gid))
    assert df.shape[0] == 1
Exemplo n.º 2
0
async def on_ready():
    '''
    Initial discord call when launching bot.
    '''
    DataProcessor._on_ready(client.guilds)