def to_mock(self):
        """Returns an AsyncMock matching the spec for this class"""
        # we still have to set stuff manually but changing values is nicer
        mock = AsyncMock(name="Message Mock", spec=discord.Message)

        # Author section
        mock.author = MockedMember(
            name=self.author["name"],
            member_id=self.author["id"],
            is_bot=self.author["is_bot"],
        ).to_mock()

        # Guild options and 'is_in_guild' are mutually exclusive
        if not self.is_in_guild:
            mock.guild = None
        else:
            mock.guild = MockedGuild(name=self.guild["name"], guild_id=self.guild["id"]).to_mock()

        mock.channel = MockedChannel().to_mock()
        mock.created_at = datetime.datetime.now()

        mock.id = self.message_id
        mock.content = self.content
        mock.clean_content = self.clean_content

        return mock
Beispiel #2
0
def context(
    dpy_guild: discord.Guild,
    dpy_channel: discord.TextChannel,
    dpy_author: discord.User,
    dpy_message: discord.Message,
) -> discord.Interaction:
    stub = AsyncMock(spec=commands.Context)
    stub.guild = dpy_guild
    stub.channel = dpy_channel
    stub.channel_id = dpy_channel.id
    stub.author = dpy_author
    stub.message = dpy_message
    return stub
Beispiel #3
0
 def test_mention_self(self):
     bot = Bot("app_name", "version")
     bot.enforce_write_permission = False
     bot.client.user.id = "12345"
     simple_callback = AsyncMock()
     bot.register_command("test", simple_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "<@12345> test arg0 arg1"
     message.author = bot.client.user
     self._await(bot.on_message(message))
     simple_callback.assert_not_awaited()
     watcher_callback.assert_not_awaited()
     fallback_callback.assert_not_awaited()