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
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()
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)
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")
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)
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)
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)
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()
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()
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
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)
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)
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)
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)
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)
def test_interaction_getter(bot, interaction, command): assert InteractionContext(bot=bot, interaction=interaction, command=command).interaction == interaction
def test_channel_getter(bot, interaction, command): assert InteractionContext(bot=bot, interaction=interaction, command=command).channel == interaction.channel
def test_guild_getter(bot, interaction, command): assert InteractionContext(bot=bot, interaction=interaction, command=command).guild == interaction.guild
def test_message_getter(bot, interaction, command): assert InteractionContext(bot=bot, interaction=interaction, command=command).message == interaction.message
def test_author_getter(bot, interaction, command): assert InteractionContext(bot=bot, interaction=interaction, command=command).author == interaction.user
def test_command_getter(bot, interaction, command): assert InteractionContext(bot=bot, interaction=interaction, command=command).command == command