Exemplo n.º 1
0
def test_on_guild_join(gid, obj_guild):
    # Make sure guild is removed from guilds table
    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

    # Make sure guild is removed from days table
    DataConnector.run_query("DELETE FROM {}.days WHERE guild_id='{}'".format(
        SCHEMA_NAME, gid))
    df = DataConnector.read_data(
        "SELECT * FROM {}.days WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 0

    # Check on guild join
    DataProcessor._on_guild_join(obj_guild)
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1

    # Also very the days table
    df = DataConnector.read_data(
        "SELECT * FROM {}.days WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1

    # Check that the size doesn't change on the same guild
    DataProcessor._on_guild_join(obj_guild)
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1

    df = DataConnector.read_data(
        "SELECT * FROM {}.days WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1
Exemplo n.º 2
0
def test_on_message_watch_channel(gid, obj_guild):
    DataProcessor._on_guild_join(obj_guild)

    cid = '1234567890'
    DataProcessor._on_message_watch_channel(gid, cid)
    df = DataConnector.read_data(
        "SELECT channel_id FROM {}.guilds WHERE guild_id='{}'".format(
            SCHEMA_NAME, gid))
    assert df['channel_id'][0] == cid

    DataProcessor._on_guild_join(obj_guild)
Exemplo n.º 3
0
def test_on_message_watch_message(gid, obj_guild):
    DataProcessor._on_guild_join(obj_guild)

    mid = '1234567890'
    DataProcessor._on_message_watch_message(gid, mid)
    df = DataConnector.read_data(
        "SELECT message_id FROM {}.guilds WHERE guild_id='{}'".format(
            SCHEMA_NAME, gid))
    assert df['message_id'][0] == mid

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

    DataProcessor._on_guild_join(obj_guild)
Exemplo n.º 4
0
def test_on_guild_remove(gid, obj_guild):
    DataProcessor._on_guild_join(obj_guild)

    # Ensure that size 1
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1
    df = DataConnector.read_data(
        "SELECT * FROM {}.days WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 1

    # Remove the guild and verify none in guilds and days tables
    DataProcessor._on_guild_remove(obj_guild)
    df = DataConnector.read_data(
        "SELECT * FROM {}.guilds WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 0
    df = DataConnector.read_data(
        "SELECT * FROM {}.days WHERE guild_id='{}'".format(SCHEMA_NAME, gid))
    assert df.shape[0] == 0

    DataProcessor._on_guild_join(obj_guild)
Exemplo n.º 5
0
async def on_guild_join(guild):
    '''
    Discord call when bot joins a new guild.
    '''
    DataProcessor._on_guild_join(guild)