Beispiel #1
0
def test_command_setter(bot, interaction, command):
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    new_command = mock.Mock()
    clazz.command = new_command
    assert clazz.command == new_command
Beispiel #2
0
async def test_typing_starts_follow_up(bot, interaction, command):
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    async with clazz.typing():
        pass
    assert clazz.follow_up
    interaction.response.defer.assert_called_once()
Beispiel #3
0
async def test_send_follow_up_file_only(file, bot, interaction, command):
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    async with clazz.typing():
        await clazz.send(file=file)
    interaction.response.defer.assert_called_once()
    interaction.followup.send.assert_called_once_with("", file=file)
Beispiel #4
0
async def test_send_follow_up_delete_after_no_webhook_message(
        bot, interaction, command):
    interaction.followup.send.return_value = None
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    async with clazz.typing():
        await clazz.send("hi", delete_after=2)
    interaction.response.defer.assert_called_once()
    interaction.followup.send.assert_called_once_with("hi")
Beispiel #5
0
async def test_send_follow_up_all_args_embeds(file, embed, bot, interaction,
                                              command):
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    async with clazz.typing():
        await clazz.send("hi", embeds=[embed], file=file)
    interaction.response.defer.assert_called_once()
    interaction.followup.send.assert_called_once_with("hi",
                                                      embeds=[embed],
                                                      file=file)
Beispiel #6
0
def test_ctor_empty_interaction_options(bot, interaction, command):
    interaction.data = {"options": []}
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    assert clazz.view.buffer == ""
    assert_class_setup(clazz, bot)
Beispiel #7
0
def test_ctor_command_single_option(bot, interaction, command):
    interaction.data = {"options": [{"name": "first", "value": "one"}]}
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    assert clazz.view.buffer == "one"
    assert_class_setup(clazz, bot)
Beispiel #8
0
async def test_send_response_file_ignored(file, bot, interaction, command):
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    await clazz.send(file=file)
    interaction.response.send_message.assert_called_once_with("")
    interaction.original_message.assert_not_called()
Beispiel #9
0
async def test_send_response_embed_only(embed, bot, interaction, command):
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    await clazz.send(embed=embed)
    interaction.response.send_message.assert_called_once_with("", embed=embed)
    interaction.original_message.assert_not_called()
Beispiel #10
0
def test_voice_client_getter(bot, interaction, command):
    voice = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command).voice_client
    if interaction.guild:
        assert voice is interaction.guild.voice_client
    else:
        assert voice is None
Beispiel #11
0
def test_ctor_subcommand_empty_options_no_subcommand_name(
        bot, interaction, command):
    command._discordpy_include_subcommand_name = {"sub": False}
    interaction.data = {"options": [{"name": "sub"}]}
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    assert clazz.view.buffer == ""
    assert_class_setup(clazz, bot)
Beispiel #12
0
async def test_send_response_delete_after(interaction_message, bot,
                                          interaction, command):
    interaction.original_message.return_value = interaction_message
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    await clazz.send("hi", delete_after=2)
    interaction.response.send_message.assert_called_once_with("hi")
    interaction_message.delete.assert_called_once_with(delay=2)
Beispiel #13
0
def test_ctor_command_options(bot, interaction, command):
    interaction.data = {
        "options": [{
            "name": "first",
            "value": "one"
        }, {
            "name": "second",
            "value": "two"
        }]
    }
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    assert clazz.view.buffer == "「one」 「two」"
    assert_class_setup(clazz, bot)
Beispiel #14
0
def test_ctor_subcommand_single_option(bot, interaction, command):
    command._discordpy_include_subcommand_name = {"sub": True}
    interaction.data = {
        "options": [{
            "name": "sub",
            "options": [{
                "name": "first",
                "value": "one"
            }]
        }]
    }
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    assert clazz.view.buffer == "sub 「one」"
    assert_class_setup(clazz, bot)
Beispiel #15
0
def test_ctor_subcommand_options_no_subcommand_name(bot, interaction, command):
    command._discordpy_include_subcommand_name = {"sub": False}
    interaction.data = {
        "options": [{
            "name":
            "sub",
            "options": [{
                "name": "first",
                "value": "one"
            }, {
                "name": "second",
                "value": "two"
            }]
        }]
    }
    clazz = InteractionContext(bot=bot,
                               interaction=interaction,
                               command=command)
    assert clazz.view.buffer == "「one」 「two」"
    assert_class_setup(clazz, bot)
Beispiel #16
0
def test_interaction_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).interaction == interaction
Beispiel #17
0
def test_channel_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).channel == interaction.channel
Beispiel #18
0
def test_guild_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).guild == interaction.guild
Beispiel #19
0
def test_message_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).message == interaction.message
Beispiel #20
0
def test_author_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).author == interaction.user
Beispiel #21
0
def test_command_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).command == command