diff options
author | 2023-02-28 21:38:57 +0200 | |
---|---|---|
committer | 2023-02-28 21:38:57 +0200 | |
commit | 66627a91334d07106ecc0ccb594755f841309c08 (patch) | |
tree | 9c05aa0971ac50336506efa6c52c097678a665fc /tests/helpers.py | |
parent | Fix antispam alerting (diff) | |
parent | Merge pull request #2421 from shtlrs/bump-pydis-core-to-9-5-0 (diff) |
Merge branch 'main' into new-filters
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 35a8a71f7..020f1aee5 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -9,9 +9,9 @@ from typing import Iterable, Optional import discord from aiohttp import ClientSession -from botcore.async_stats import AsyncStatsClient -from botcore.site_api import APIClient from discord.ext.commands import Context +from pydis_core.async_stats import AsyncStatsClient +from pydis_core.site_api import APIClient from bot.bot import Bot from tests._autospec import autospec # noqa: F401 other modules import it via this module @@ -222,7 +222,7 @@ class MockRole(CustomMockMixin, unittest.mock.Mock, ColourMixin, HashableMixin): # Create a Member instance to get a realistic Mock of `discord.Member` -member_data = {'user': 'lemon', 'roles': [1]} +member_data = {'user': 'lemon', 'roles': [1], 'flags': 2} state_mock = unittest.mock.MagicMock() member_instance = discord.Member(data=member_data, guild=guild_instance, state=state_mock) @@ -479,6 +479,25 @@ class MockContext(CustomMockMixin, unittest.mock.MagicMock): self.invoked_from_error_handler = kwargs.get('invoked_from_error_handler', False) +class MockInteraction(CustomMockMixin, unittest.mock.MagicMock): + """ + A MagicMock subclass to mock Interaction objects. + + Instances of this class will follow the specifications of `discord.Interaction` + instances. For more information, see the `MockGuild` docstring. + """ + + def __init__(self, **kwargs) -> None: + super().__init__(**kwargs) + self.me = kwargs.get('me', MockMember()) + self.client = kwargs.get('client', MockBot()) + self.guild = kwargs.get('guild', MockGuild()) + self.user = kwargs.get('user', MockMember()) + self.channel = kwargs.get('channel', MockTextChannel()) + self.message = kwargs.get('message', MockMessage()) + self.invoked_from_error_handler = kwargs.get('invoked_from_error_handler', False) + + attachment_instance = discord.Attachment(data=unittest.mock.MagicMock(id=1), state=unittest.mock.MagicMock()) @@ -530,6 +549,16 @@ class MockMessage(CustomMockMixin, unittest.mock.MagicMock): self.channel = kwargs.get('channel', MockTextChannel()) +class MockInteractionMessage(MockMessage): + """ + A MagicMock subclass to mock InteractionMessage objects. + + Instances of this class will follow the specifications of `discord.InteractionMessage` instances. For more + information, see the `MockGuild` docstring. + """ + pass + + emoji_data = {'require_colons': True, 'managed': True, 'id': 1, 'name': 'hyperlemon'} emoji_instance = discord.Emoji(guild=MockGuild(), state=unittest.mock.MagicMock(), data=emoji_data) |