def ctx(): return mock.MagicMock(spec_set=context.Context( mock.MagicMock(spec_set=Bot), mock.MagicMock(spec_set=messages.Message), "", "", mock.MagicMock(spec_set=commands.Command), ))
def get_context(self, message: hikari.Message, prefix: str, invoked_with: str, invoked_command: commands.Command) -> context_.Context: """ Get the :obj:`~.context.Context` instance for the given arguments. This should be overridden if you wish to supply a custom :obj:`~.context.Context` class to your commands. Args: message (:obj:`hikari.Message`): The message the context is for. prefix (:obj:`str`): The prefix used in this context. invoked_with (:obj:`str`): The command name/alias used to trigger invocation. invoked_command (:obj:`~.commands.Command`): The command that will be invoked. Returns: :obj:`~.context.Context`: The context to be used for the command invocation. """ return context_.Context(self, message, prefix, invoked_with, invoked_command)
async def test_context_reply(bot, message, command): ctx = context.Context(bot, message, "", "", command) msg = "super cool message" await ctx.respond(msg) message.respond.assert_called_with(msg)
async def test_context_edited_timestamp_property(bot, message, command): ctx = context.Context(bot, message, "", "", command) dt = datetime.datetime.now() ctx.message.edited_timestamp = dt assert ctx.edited_timestamp is dt
async def test_context_message_id_property(bot, message, command): ctx = context.Context(bot, message, "", "", command) ctx.message.id = 123456 assert ctx.message_id == 123456
async def test_context_member_property(bot, message, command): ctx = context.Context(bot, message, "", "", command) mem = mock.MagicMock(spec_set=guilds.Member) ctx.message.member = mem assert ctx.member is mem
async def test_context_content_property(bot, message, command): ctx = context.Context(bot, message, "", "", command) ctx.message.content = "super cool message" assert ctx.content == "super cool message"