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 build_interaction(
    guild: discord.Guild,
    channel: discord.TextChannel,
    author: discord.User,
) -> discord.Interaction:
    stub = AsyncMock(spec=discord.Interaction)
    stub.response = AsyncMock()
    stub.followup = AsyncMock()
    stub.guild = guild
    stub.guild_id = guild.id
    stub.channel = channel
    stub.channel_id = channel.id
    stub.user = author
    stub.original_message = AsyncMock(
        return_value=build_message(guild, channel, author))
    return stub