def test_slash_command_patches_adapt_name_to_parent_as_given_value(): parent = command()(func) cmd = command(parent=parent)(func) slash_command(root="root", name="name", discordpy_include_subcommand_name=False)(cmd) assert parent._discordpy_include_subcommand_name == {"name": False}
def test_slash_command_patches_adapt_name_to_parent_multiple(): parent = command()(func) cmd1 = command(parent=parent)(func) cmd2 = command(parent=parent)(func) slash_command(root="root", name="name1")(cmd1) slash_command(root="root", name="name2")(cmd2) assert parent._discordpy_include_subcommand_name == { "name1": True, "name2": True }
async def test_handle_slash_interaction_calls_command_invoke( bot, interaction, command): bot.commands = [command] command.name = "command_name" command.description = "command_desc" slash_command()(command) interaction.data = {"name": "command_name"} clazz = SlashCommandHandler(bot) await clazz.handle_slash_interaction(interaction) command.invoke.assert_called_once()
async def test_handle_slash_interaction_no_matching_command( bot, interaction, command): bot.commands = [command] command.name = "some_other_command" command.description = "command_desc" slash_command()(command) interaction.data = {"name": "command_name"} clazz = SlashCommandHandler(bot) await clazz.handle_slash_interaction(interaction) command.invoke.assert_not_called()
def test_slash_command_slash_options_subcommand(): options = [Option(name="opt", description="desc")] slash = slash_command(root="root", name="name", options=options)(command()(func)) assert slash.slash_ext.options == [ SubCommand(name="name", description=None, type=OptionType.SUB_COMMAND, options=options) ]
def test_slash_command_slash_name_is_command_name(): slash = slash_command()(command(name="name")(func)) assert slash.slash_ext.name == "name"
def test_slash_command_slash_name_is_root(): slash = slash_command(root="root", name="name")(command()(func)) assert slash.slash_ext.name == "root"
def test_slash_command_creates_slash_ext(): slash = slash_command()(command()(func)) assert slash.slash_ext is not None
def test_slash_command_patches_copy(): cmd = command()(func) slash_command(root="root", name="name")(cmd) copy = cmd.copy() assert copy._discordpy_include_subcommand_name == cmd._discordpy_include_subcommand_name assert copy.slash_ext == cmd.slash_ext
def create_slash_command(command, command_name, **kwargs): command.name = command_name command.description = f"description for {command_name}" slash_command(**kwargs)(command)
def test_slash_command_slash_description_is_command_name(): slash = slash_command()(command(name="name")(func)) assert slash.slash_ext.description == "name"
def test_slash_command_name_but_no_root(): with pytest.raises(ValueError): slash_command(root=None, name="name")(command()(func))
def test_slash_command_root_but_no_name(): with pytest.raises(ValueError): slash_command(root="root", name=None)(command()(func))
def test_slash_command_patches_adapt_name(): cmd = command()(func) slash_command(root="root", name="name")(cmd) assert cmd._discordpy_include_subcommand_name == {"name": True}
def test_slash_command_slash_options_is_provided(): options = [Option(name="opt", description="desc")] slash = slash_command(options=options)(command()(func)) assert slash.slash_ext.options == options
def test_slash_command_slash_description_is_root(): slash = slash_command(root="root", name="name")(command()(func)) assert slash.slash_ext.description == "root"
def test_slash_command_slash_description_is_command_description(): slash = slash_command()(command(description="desc")(func)) assert slash.slash_ext.description == "desc"
def test_slash_command_patches_adapt_name_to_parent(): parent = command()(func) cmd = command(parent=parent)(func) slash_command(root="root", name="name")(cmd) assert parent._discordpy_include_subcommand_name == {"name": True}
def test_slash_command_slash_options_is_empty(): slash = slash_command()(command()(func)) assert slash.slash_ext.options == []
def test_get_slash_command_slash_command(): cmd = discord.ext.commands.command()(func) slash_command(root="root", name="name")(cmd) assert get_slash_command(cmd) is cmd.slash_ext