diff options
author | 2020-07-13 15:04:40 +0200 | |
---|---|---|
committer | 2020-07-13 15:04:40 +0200 | |
commit | c4e9060a76a901c7d2e6035e6ca19d51770a4ab3 (patch) | |
tree | bf691a2940cd1593eb27dcd1af9f3459a116421e /tests | |
parent | Merge d.py version bump from master branch (diff) |
Incidents: add `download_file` helper & tests
Co-authored-by: MarkKoz <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bot/cogs/moderation/test_incidents.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/bot/cogs/moderation/test_incidents.py b/tests/bot/cogs/moderation/test_incidents.py index 789a37cd4..273916199 100644 --- a/tests/bot/cogs/moderation/test_incidents.py +++ b/tests/bot/cogs/moderation/test_incidents.py @@ -12,6 +12,7 @@ from bot.cogs.moderation import Incidents, incidents from bot.constants import Colours from tests.helpers import ( MockAsyncWebhook, + MockAttachment, MockBot, MockMember, MockMessage, @@ -69,6 +70,25 @@ mock_404 = discord.NotFound( ) +class TestDownloadFile(unittest.IsolatedAsyncioTestCase): + """Collection of tests for the `download_file` helper function.""" + + async def test_download_file_success(self): + """If `to_file` succeeds, function returns the acquired `discord.File`.""" + file = MagicMock(discord.File, filename="bigbadlemon.jpg") + attachment = MockAttachment(to_file=AsyncMock(return_value=file)) + + acquired_file = await incidents.download_file(attachment) + self.assertIs(file, acquired_file) + + async def test_download_file_fail(self): + """If `to_file` fails, function handles the exception & returns None.""" + attachment = MockAttachment(to_file=AsyncMock(side_effect=mock_404)) + + acquired_file = await incidents.download_file(attachment) + self.assertIsNone(acquired_file) + + class TestMakeEmbed(unittest.TestCase): """Collection of tests for the `make_embed` helper function.""" |