示例#1
0
async def test_delete_all_offline_streams(twitch_alert_db_manager_tables,
                                          bot: discord.ext.commands.Bot):
    message_id = (await dpytest.message("test_msg",
                                        bot.guilds[0].channels[0])).id
    sql_add_message = insert(UserInTwitchAlert).values(
        channel_id=bot.guilds[0].channels[0].id,
        twitch_username='******',
        custom_message=None,
        message_id=message_id)
    with session_manager() as session:
        session.execute(sql_add_message)
        session.commit()

        await twitch_alert_db_manager_tables.delete_all_offline_streams(
            ['monstercat'])

        sql_select_messages = select(UserInTwitchAlert).where(
            and_(UserInTwitchAlert.twitch_username == 'monstercat',
                 UserInTwitchAlert.channel_id == bot.guilds[0].channels[0].id))
        result = session.execute(sql_select_messages).scalars().one_or_none()

        assert result is not None
        assert result.message_id is None
        with pytest.raises(discord.errors.NotFound, match="Unknown Message"):
            await bot.guilds[0].channels[0].fetch_message(message_id)
示例#2
0
async def test_remove_team_from_twitch_alert_wrong_guild(twitch_cog):
    guild = dpytest.backend.make_guild(name="TestGuild")
    channel = dpytest.backend.make_text_channel(name="TestChannel",
                                                guild=guild)
    dpytest.get_config().guilds.append(guild)
    dpytest.get_config().channels.append(channel)
    member = await dpytest.member_join(1, name="TestUser", discrim=1)
    await dpytest.member_join(1, dpytest.get_config().client.user)

    with pytest.raises(
            discord.ext.commands.errors.ChannelNotFound,
            match=
            f"Channel \"{dpytest.get_config().channels[0].id}\" not found."):
        await dpytest.message(
            f"{koalabot.COMMAND_PREFIX}twitch addTeam faze {dpytest.get_config().channels[0].id}",
            channel=-1,
            member=member)
async def test_delete_all_offline_streams(twitch_alert_db_manager_tables,
                                          bot: discord.ext.commands.Bot):
    message_id = (await dpytest.message("test_msg",
                                        bot.guilds[0].channels[0])).id
    sql_add_message = "INSERT INTO UserInTwitchAlert(channel_id, twitch_username, custom_message, message_id) " \
                      f"VALUES({bot.guilds[0].channels[0].id},'monstercat',Null,{message_id}) "
    twitch_alert_db_manager_tables.get_parent_database_manager(
    ).db_execute_commit(sql_add_message)
    await twitch_alert_db_manager_tables.delete_all_offline_streams(
        False, ['monstercat'])
    sql_select_messages = "SELECT message_id,twitch_username FROM UserInTwitchAlert " \
                          f"WHERE twitch_username = '******' AND channel_id = {bot.guilds[0].channels[0].id}"
    result = twitch_alert_db_manager_tables.get_parent_database_manager(
    ).db_execute_select(sql_select_messages)
    assert len(result) == 1
    assert result[0][0] is None
    with pytest.raises(discord.errors.NotFound, match="Unknown Message"):
        await bot.guilds[0].channels[0].fetch_message(message_id)
    pass
async def test_remove_team_from_ta_invalid(twitch_alert_db_manager_tables):
    with pytest.raises(AttributeError, match="Team name not found"):
        await twitch_alert_db_manager_tables.remove_team_from_ta(590, 590)