aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/bot/exts/utils/test_snekbox.py6
-rw-r--r--tests/bot/utils/test_services.py21
2 files changed, 17 insertions, 10 deletions
diff --git a/tests/bot/exts/utils/test_snekbox.py b/tests/bot/exts/utils/test_snekbox.py
index 3c555c051..b870a9945 100644
--- a/tests/bot/exts/utils/test_snekbox.py
+++ b/tests/bot/exts/utils/test_snekbox.py
@@ -35,15 +35,15 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
resp.json.assert_awaited_once()
async def test_upload_output_reject_too_long(self):
- """Reject output longer than MAX_PASTE_LEN."""
- result = await self.cog.upload_output("-" * (snekbox.MAX_PASTE_LEN + 1))
+ """Reject output longer than MAX_PASTE_LENGTH."""
+ result = await self.cog.upload_output("-" * (snekbox.MAX_PASTE_LENGTH + 1))
self.assertEqual(result, "too long to upload")
@patch("bot.exts.utils.snekbox.send_to_paste_service")
async def test_upload_output(self, mock_paste_util):
"""Upload the eval output to the URLs.paste_service.format(key="documents") endpoint."""
await self.cog.upload_output("Test output.")
- mock_paste_util.assert_called_once_with("Test output.", extension="txt")
+ mock_paste_util.assert_called_once_with("Test output.", extension="txt", max_length=snekbox.MAX_PASTE_LENGTH)
async def test_codeblock_converter(self):
ctx = MockContext()
diff --git a/tests/bot/utils/test_services.py b/tests/bot/utils/test_services.py
index 3b71022db..de166c813 100644
--- a/tests/bot/utils/test_services.py
+++ b/tests/bot/utils/test_services.py
@@ -4,7 +4,9 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch
from aiohttp import ClientConnectorError
-from bot.utils.services import FAILED_REQUEST_ATTEMPTS, send_to_paste_service
+from bot.utils.services import (
+ FAILED_REQUEST_ATTEMPTS, MAX_PASTE_LENGTH, PasteTooLongError, PasteUploadError, send_to_paste_service
+)
from tests.helpers import MockBot
@@ -55,23 +57,28 @@ class PasteTests(unittest.IsolatedAsyncioTestCase):
for error_json in test_cases:
with self.subTest(error_json=error_json):
response.json = AsyncMock(return_value=error_json)
- result = await send_to_paste_service("")
+ with self.assertRaises(PasteUploadError):
+ await send_to_paste_service("")
self.assertEqual(self.bot.http_session.post.call_count, FAILED_REQUEST_ATTEMPTS)
- self.assertIsNone(result)
self.bot.http_session.post.reset_mock()
async def test_request_repeated_on_connection_errors(self):
"""Requests are repeated in the case of connection errors."""
self.bot.http_session.post = MagicMock(side_effect=ClientConnectorError(Mock(), Mock()))
- result = await send_to_paste_service("")
+ with self.assertRaises(PasteUploadError):
+ await send_to_paste_service("")
self.assertEqual(self.bot.http_session.post.call_count, FAILED_REQUEST_ATTEMPTS)
- self.assertIsNone(result)
async def test_general_error_handled_and_request_repeated(self):
"""All `Exception`s are handled, logged and request repeated."""
self.bot.http_session.post = MagicMock(side_effect=Exception)
- result = await send_to_paste_service("")
+ with self.assertRaises(PasteUploadError):
+ await send_to_paste_service("")
self.assertEqual(self.bot.http_session.post.call_count, FAILED_REQUEST_ATTEMPTS)
self.assertLogs("bot.utils", logging.ERROR)
- self.assertIsNone(result)
+
+ async def test_raises_error_on_too_long_input(self):
+ contents = "a" * (MAX_PASTE_LENGTH+1)
+ with self.assertRaises(PasteTooLongError):
+ await send_to_paste_service(contents)