diff options
author | 2023-06-22 22:33:50 +0100 | |
---|---|---|
committer | 2023-07-11 15:45:09 +0100 | |
commit | d961f5e2cc89c6c2a30b923756e3304d65f1ae28 (patch) | |
tree | d8961c450f00e77b2b3e08918e9dfc83da86819f | |
parent | Remove unneeded paste service constant (diff) |
Mock _lexers_supported_by_pastebin in test to ensure no call to external service is made
-rw-r--r-- | bot/exts/utils/snekbox/_cog.py | 9 | ||||
-rw-r--r-- | tests/bot/exts/utils/snekbox/test_snekbox.py | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py index f07bcb7df..875357fb3 100644 --- a/bot/exts/utils/snekbox/_cog.py +++ b/bot/exts/utils/snekbox/_cog.py @@ -10,8 +10,7 @@ from typing import Literal, NamedTuple, TYPE_CHECKING from discord import AllowedMentions, HTTPException, Interaction, Message, NotFound, Reaction, User, enums, ui from discord.ext.commands import Cog, Command, Context, Converter, command, guild_only -from pydis_core.utils import interactions -from pydis_core.utils.paste_service import PasteTooLongError, PasteUploadError, send_to_paste_service +from pydis_core.utils import interactions, paste_service from pydis_core.utils.regex import FORMATTED_CODE_REGEX, RAW_CODE_REGEX from bot.bot import Bot @@ -208,15 +207,15 @@ class Snekbox(Cog): log.trace("Uploading full output to paste service...") try: - paste_link = await send_to_paste_service( + paste_link = await paste_service.send_to_paste_service( contents=output, lexer="text", http_session=self.bot.http_session, ) return paste_link["link"] - except PasteTooLongError: + except paste_service.PasteTooLongError: return "too long to upload" - except PasteUploadError: + except paste_service.PasteUploadError: return "unable to upload" @staticmethod diff --git a/tests/bot/exts/utils/snekbox/test_snekbox.py b/tests/bot/exts/utils/snekbox/test_snekbox.py index 6d9b6b1e4..200aa5a20 100644 --- a/tests/bot/exts/utils/snekbox/test_snekbox.py +++ b/tests/bot/exts/utils/snekbox/test_snekbox.py @@ -55,6 +55,10 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase): ) resp.json.assert_awaited_once() + @patch( + "bot.exts.utils.snekbox._cog.paste_service._lexers_supported_by_pastebin", + {"https://paste.pythondiscord.com": ["text"]}, + ) async def test_upload_output_reject_too_long(self): """Reject output longer than MAX_PASTE_LENGTH.""" result = await self.cog.upload_output("-" * (MAX_PASTE_SIZE + 1)) |