diff options
author | 2020-05-20 10:48:22 +0300 | |
---|---|---|
committer | 2020-05-20 10:48:22 +0300 | |
commit | 4c47697e6f70fdb0dc20414557b93e899834d877 (patch) | |
tree | 31d91e8338babe40d057a68a0e09160d46549e10 /tests/helpers.py | |
parent | Infraction Tests: Small fixes (diff) | |
parent | Merge pull request #944 from Numerlor/eval-timeout-increase (diff) |
Merge branch 'master' into ban-kick-reason-length
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 227bac95f..91d814b3a 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -319,7 +319,7 @@ class MockTextChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin): """ spec_set = channel_instance - def __init__(self, name: str = 'channel', channel_id: int = 1, **kwargs) -> None: + def __init__(self, **kwargs) -> None: default_kwargs = {'id': next(self.discord_id), 'name': 'channel', 'guild': MockGuild()} super().__init__(**collections.ChainMap(kwargs, default_kwargs)) @@ -327,6 +327,27 @@ class MockTextChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin): self.mention = f"#{self.name}" +# Create data for the DMChannel instance +state = unittest.mock.MagicMock() +me = unittest.mock.MagicMock() +dm_channel_data = {"id": 1, "recipients": [unittest.mock.MagicMock()]} +dm_channel_instance = discord.DMChannel(me=me, state=state, data=dm_channel_data) + + +class MockDMChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin): + """ + A MagicMock subclass to mock TextChannel objects. + + Instances of this class will follow the specifications of `discord.TextChannel` instances. For + more information, see the `MockGuild` docstring. + """ + spec_set = dm_channel_instance + + def __init__(self, **kwargs) -> None: + default_kwargs = {'id': next(self.discord_id), 'recipient': MockUser(), "me": MockUser()} + super().__init__(**collections.ChainMap(kwargs, default_kwargs)) + + # Create a Message instance to get a realistic MagicMock of `discord.Message` message_data = { 'id': 1, |