aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-11-15 01:37:02 +0100
committerGravatar Sebastiaan Zeeff <[email protected]>2019-11-15 01:37:02 +0100
commitb42a7b5b7f2c1c9f9924eeb9d39f7767306824ec (patch)
tree96b6ce82605401a590b3def2a5a3c66723291896 /tests
parentAdjust MockReaction for new AsyncIteratorMock protocol (diff)
Add MockAsyncWebhook to mock `discord.Webhook` objects
I have added a mock type to mock `discord.Webhook` instances. Note that the current type is specifically meant to mock webhooks that use an AsyncAdaptor and therefore has AsyncMock/coroutine mocks for the "maybe-coroutine" methods specified in the `discord.py` docs.
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index 13852397f..b2daae92d 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -502,3 +502,24 @@ class MockReaction(CustomMockMixin, unittest.mock.MagicMock):
self.message = kwargs.get('message', MockMessage())
self.users = AsyncIteratorMock(kwargs.get('users', []))
+
+webhook_instance = discord.Webhook(data=unittest.mock.MagicMock(), adapter=unittest.mock.MagicMock())
+
+
+class MockAsyncWebhook(CustomMockMixin, unittest.mock.MagicMock):
+ """
+ A MagicMock subclass to mock Webhook objects using an AsyncWebhookAdapter.
+
+ Instances of this class will follow the specifications of `discord.Webhook` instances. For
+ more information, see the `MockGuild` docstring.
+ """
+
+ def __init__(self, **kwargs) -> None:
+ super().__init__(spec_set=webhook_instance, **kwargs)
+
+ # Because Webhooks can also use a synchronous "WebhookAdapter", the methods are not defined
+ # as coroutines. That's why we need to set the methods manually.
+ self.send = AsyncMock()
+ self.edit = AsyncMock()
+ self.delete = AsyncMock()
+ self.execute = AsyncMock()