aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Den4200 <[email protected]>2020-07-06 17:08:24 +0000
committerGravatar Den4200 <[email protected]>2020-07-06 17:08:24 +0000
commit2d170b8af92c77bedea4d77fbdeedc515d3f2c59 (patch)
tree470f3581a2ca912d296aa62c0cb7eb837ce1b841
parentAdd multiple test cases for set_slowmode tests (diff)
Improve set_slowmode tests by checking whether the channel was edited
-rw-r--r--tests/bot/cogs/test_slowmode.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/tests/bot/cogs/test_slowmode.py b/tests/bot/cogs/test_slowmode.py
index e9835b8bd..65b1534cb 100644
--- a/tests/bot/cogs/test_slowmode.py
+++ b/tests/bot/cogs/test_slowmode.py
@@ -32,20 +32,27 @@ class SlowmodeTests(unittest.IsolatedAsyncioTestCase):
async def test_set_slowmode_no_channel(self) -> None:
"""Set slowmode without a given channel."""
test_cases = (
- ('helpers', 23, f'{Emojis.check_mark} The slowmode delay for #helpers is now 23 seconds.'),
- ('mods', 76526, f'{Emojis.cross_mark} The slowmode delay must be between 0 and 6 hours.'),
- ('admins', 97, f'{Emojis.check_mark} The slowmode delay for #admins is now 1 minute and 37 seconds.')
+ ('helpers', 23, True, f'{Emojis.check_mark} The slowmode delay for #helpers is now 23 seconds.'),
+ ('mods', 76526, False, f'{Emojis.cross_mark} The slowmode delay must be between 0 and 6 hours.'),
+ ('admins', 97, True, f'{Emojis.check_mark} The slowmode delay for #admins is now 1 minute and 37 seconds.')
)
- for channel_name, seconds, result_msg in test_cases:
+ for channel_name, seconds, edited, result_msg in test_cases:
with self.subTest(
channel_mention=channel_name,
seconds=seconds,
+ edited=edited,
result_msg=result_msg
):
self.ctx.channel = MockTextChannel(name=channel_name)
await self.cog.set_slowmode(self.cog, self.ctx, None, relativedelta(seconds=seconds))
+
+ if edited:
+ self.ctx.channel.edit.assert_awaited_once_with(slowmode_delay=float(seconds))
+ else:
+ self.ctx.channel.edit.assert_not_called()
+
self.ctx.send.assert_called_once_with(result_msg)
self.ctx.reset_mock()
@@ -53,20 +60,27 @@ class SlowmodeTests(unittest.IsolatedAsyncioTestCase):
async def test_set_slowmode_with_channel(self) -> None:
"""Set slowmode with a given channel."""
test_cases = (
- ('bot-commands', 12, f'{Emojis.check_mark} The slowmode delay for #bot-commands is now 12 seconds.'),
- ('mod-spam', 21, f'{Emojis.check_mark} The slowmode delay for #mod-spam is now 21 seconds.'),
- ('admin-spam', 4323598, f'{Emojis.cross_mark} The slowmode delay must be between 0 and 6 hours.')
+ ('bot-commands', 12, True, f'{Emojis.check_mark} The slowmode delay for #bot-commands is now 12 seconds.'),
+ ('mod-spam', 21, True, f'{Emojis.check_mark} The slowmode delay for #mod-spam is now 21 seconds.'),
+ ('admin-spam', 4323598, False, f'{Emojis.cross_mark} The slowmode delay must be between 0 and 6 hours.')
)
- for channel_name, seconds, result_msg in test_cases:
+ for channel_name, seconds, edited, result_msg in test_cases:
with self.subTest(
channel_mention=channel_name,
seconds=seconds,
+ edited=edited,
result_msg=result_msg
):
text_channel = MockTextChannel(name=channel_name)
await self.cog.set_slowmode(self.cog, self.ctx, text_channel, relativedelta(seconds=seconds))
+
+ if edited:
+ text_channel.edit.assert_awaited_once_with(slowmode_delay=float(seconds))
+ else:
+ text_channel.edit.assert_not_called()
+
self.ctx.send.assert_called_once_with(result_msg)
self.ctx.reset_mock()