Esempio n. 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
Esempio n. 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()
Esempio n. 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)
Esempio n. 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")
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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()
Esempio n. 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()
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 16
0
def test_interaction_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).interaction == interaction
Esempio n. 17
0
def test_channel_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).channel == interaction.channel
Esempio n. 18
0
def test_guild_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).guild == interaction.guild
Esempio n. 19
0
def test_message_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).message == interaction.message
Esempio n. 20
0
def test_author_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).author == interaction.user
Esempio n. 21
0
def test_command_getter(bot, interaction, command):
    assert InteractionContext(bot=bot,
                              interaction=interaction,
                              command=command).command == command