示例#1
0
async def test_drive(bot):
    await dpytest.message(f"{PREFIX} drive")
    assert not dpytest.verify().message().nothing()
    message = dpytest.get_embed()

    from ICBOT.exceptions import NoArgument
    assert dpytest.embed_eq(
        message,
        NoArgument(StandardCommands.DRIVE.name).to_message())

    await dpytest.message(f"{PREFIX} drive test")
    from ICBOT.exceptions import InvalidArgument
    assert dpytest.embed_eq(
        dpytest.get_embed(),
        InvalidArgument(ErrorMessages.DRIVE_NO_FILE_SPECIFIED).to_message())
def test_create_live_embed_with_message():
    # Create the expected embed with information required
    expected = discord.Embed(colour=KOALA_GREEN, title="https://twitch.tv/test", description="Hello Message")
    expected.set_author(name="Test is now streaming!", icon_url=TwitchAlert.TWITCH_ICON)
    expected.add_field(name="Stream Title", value="Test Title")
    expected.add_field(name="Playing", value="TestGame")
    expected.set_thumbnail(url="http://koalabot.uk")

    # Create JSON required to pass to method
    stream_info = {'user_name': "Test", 'title': "Test Title"}
    user_info = {'profile_image_url': "http://koalabot.uk"}
    game_info = {'name': "TestGame"}

    # Get response and assert equal
    result = TwitchAlert.create_live_embed(stream_info, user_info, game_info, "Hello Message")
    assert dpytest.embed_eq(result, expected)
async def test_get_embed_from_message():
    config: dpytest.RunnerConfig = dpytest.get_config()
    author: discord.Member = config.members[0]
    guild: discord.Guild = config.guilds[0]
    channel: discord.TextChannel = guild.text_channels[0]
    test_embed_dict: dict = {
        'title': 'title',
        'description': 'descr',
        'type': 'rich',
        'url': 'https://www.google.com'
    }
    bot: discord.Client = config.client
    await bot.http.send_message(channel.id, '', embed=test_embed_dict)
    sent_msg: discord.Message = await dpytest.sent_queue.get()
    msg_mock: discord.Message = dpytest.back.make_message('a', author, channel)
    result = rfr_cog.get_embed_from_message(None)
    assert result is None
    result = rfr_cog.get_embed_from_message(msg_mock)
    assert result is None
    result = rfr_cog.get_embed_from_message(sent_msg)
    assert dpytest.embed_eq(result, sent_msg.embeds[0])