Пример #1
0
async def test_db_manager_update_welcome_message(guild_id, new_message,
                                                 expected):
    await add_fake_guild_to_db(guild_id)
    intro_db.update_guild_welcome_message(guild_id, new_message)
    await asyncio.sleep(0.2)
    val = intro_db.fetch_guild_welcome_message(guild_id)
    assert val == expected, intro_db.fetch_guild_welcome_message(guild_id)
Пример #2
0
async def test_on_guild_remove(bot):
    test_config = dpytest.get_config()
    guild = test_config.guilds[0]
    client = test_config.client
    bot_member = test_config.guilds[0].get_member(client.user.id)
    dpytest.backend.delete_member(bot_member)
    val = intro_db.fetch_guild_welcome_message(guild.id)
    assert val is None
Пример #3
0
async def test_on_guild_join():
    test_config = dpytest.get_config()
    client = test_config.client
    guild = dpytest.back.make_guild('TestGuildJoin', id_num=1250)
    test_config.guilds.append(guild)
    await dpytest.member_join(1, client.user)
    await asyncio.sleep(0.3)
    val = intro_db.fetch_guild_welcome_message(1250)
    assert val == DEFAULT_WELCOME_MESSAGE
Пример #4
0
async def test_update_welcome_message_too_long():
    import random, string
    guild = dpytest.get_config().guilds[0]
    old_message = get_guild_welcome_message(guild.id)
    new_message = "".join(
        random.choice(string.ascii_letters) for _ in range(1800))
    msg_mock = dpytest.back.make_message('y',
                                         dpytest.get_config().members[0],
                                         dpytest.get_config().channels[0])
    with mock.patch('discord.client.Client.wait_for',
                    mock.AsyncMock(return_value=msg_mock)):
        await dpytest.message(koalabot.COMMAND_PREFIX +
                              "update_welcome_message " + new_message)
    assert dpytest.verify().message().content(
        "Your welcome message is too long to send, sorry. The maximum character limit is 1600."
    )
    assert dpytest.verify().message().nothing()
    assert intro_db.fetch_guild_welcome_message(guild.id) != new_message
Пример #5
0
async def test_update_welcome_message_timeout():
    guild = dpytest.get_config().guilds[0]
    old_message = get_guild_welcome_message(guild.id)
    new_message = "this is a non default message"
    # msg_mock = dpytest.back.make_message('y', dpytest.get_config().members[0], dpytest.get_config().channels[0])
    with mock.patch('discord.client.Client.wait_for',
                    mock.AsyncMock(return_value=None)):
        await dpytest.message(koalabot.COMMAND_PREFIX +
                              "update_welcome_message " + new_message)

    assert dpytest.verify().message().content(
        f"""Your current welcome message is:\n\r{old_message}""")
    assert dpytest.verify().message().content(
        f"""Your new welcome message will be:\n\r{new_message}\n\r{BASE_LEGAL_MESSAGE}"""
        + """\n\rWould you like to update the message? Y/N?""")
    assert dpytest.verify().message().content("Timed out.")
    assert dpytest.verify().message().content(
        "Okay, I won't update the welcome message then.")
    assert dpytest.verify().message().nothing()
    assert intro_db.fetch_guild_welcome_message(guild.id) != new_message
Пример #6
0
async def test_db_manager_fetch_welcome_message(guild_id, expected):
    await add_fake_guild_to_db(101)
    val = intro_db.fetch_guild_welcome_message(guild_id)
    assert val == expected, str(guild_id) + f": {val}"