From c868811621da78feaa370d67d49ce4661e9cc359 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 14 Jun 2023 15:57:44 +0100 Subject: Write custom get_role func for MockMember The new d.py Member.get_role uses the Guild.get_role function if the member has the role. SInce we don't set Guild.roles overwrite this instead. --- tests/helpers.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/helpers.py b/tests/helpers.py index b5a3f2463..b7e5cc871 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -256,6 +256,9 @@ class MockMember(CustomMockMixin, unittest.mock.Mock, ColourMixin, HashableMixin if "mention" not in kwargs: self.mention = f"@{self.name}" + def get_role(self, role_id: int) -> MockRole | None: + return discord.utils.get(self.roles, id=role_id) + # Create a User instance to get a realistic Mock of `discord.User` _user_data_mock = collections.defaultdict(unittest.mock.MagicMock, { -- cgit v1.2.3 From 5f182ed25315f349b4c450b8462988d5a0c214e0 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 14 Jun 2023 15:58:20 +0100 Subject: Update MockAttachment data with new expected fields --- tests/helpers.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/helpers.py b/tests/helpers.py index b7e5cc871..26ac42697 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -525,7 +525,18 @@ class MockInteraction(CustomMockMixin, unittest.mock.MagicMock): 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()) +attachment_data = { + "id": 1, + "size": 14, + "filename": "jchrist.png", + "url": "https://google.com", + "proxy_url": "https://google.com", + "waveform": None, +} +attachment_instance = discord.Attachment( + data=attachment_data, + state=unittest.mock.MagicMock(), +) class MockAttachment(CustomMockMixin, unittest.mock.MagicMock): -- cgit v1.2.3