aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-03-10 20:36:36 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-03-10 21:39:11 +0300
commitacf2b643672703d2bc2011558e9fb68c76d0bc17 (patch)
tree6da645c5f20846f38fec4de1df8a08b2a1fea6c6
parentMerge branch 'master' into voicechannel-mute (diff)
Combine Silence Target Tests
Combine two tests that are responsible for checking the silence helper uses the correct channel and message. Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r--bot/exts/moderation/silence.py2
-rw-r--r--tests/bot/exts/moderation/test_silence.py53
2 files changed, 16 insertions, 39 deletions
diff --git a/bot/exts/moderation/silence.py b/bot/exts/moderation/silence.py
index dd379b412..616dfbefb 100644
--- a/bot/exts/moderation/silence.py
+++ b/bot/exts/moderation/silence.py
@@ -173,7 +173,7 @@ class Silence(commands.Cog):
if not await self._set_silence_overwrites(channel, kick=kick):
log.info(f"Tried to silence channel {channel_info} but the channel was already silenced.")
- await self.send_message(MSG_SILENCE_FAIL, ctx.channel, channel)
+ await self.send_message(MSG_SILENCE_FAIL, ctx.channel, channel, alert_target=False)
return
if isinstance(channel, VoiceChannel):
diff --git a/tests/bot/exts/moderation/test_silence.py b/tests/bot/exts/moderation/test_silence.py
index a52f2447d..c3b30450f 100644
--- a/tests/bot/exts/moderation/test_silence.py
+++ b/tests/bot/exts/moderation/test_silence.py
@@ -375,51 +375,28 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
self.voice_channel.overwrites_for.return_value = self.voice_overwrite
async def test_sent_correct_message(self):
- """Appropriate failure/success message was sent by the command."""
+ """Appropriate failure/success message was sent by the command to the correct channel."""
+ # The following test tuples are made up of:
+ # duration, expected message, and the success of the _set_silence_overwrites function
test_cases = (
(0.0001, silence.MSG_SILENCE_SUCCESS.format(duration=0.0001), True,),
(None, silence.MSG_SILENCE_PERMANENT, True,),
(5, silence.MSG_SILENCE_FAIL, False,),
)
+
for duration, message, was_silenced in test_cases:
- ctx = MockContext()
with mock.patch.object(self.cog, "_set_silence_overwrites", return_value=was_silenced):
- with self.subTest(was_silenced=was_silenced, message=message, duration=duration):
- await self.cog.silence.callback(self.cog, ctx, duration)
- ctx.channel.send.assert_called_once_with(message)
-
- @mock.patch.object(silence.Silence, "_set_silence_overwrites", return_value=True)
- @mock.patch.object(silence.Silence, "_force_voice_sync")
- async def test_sent_to_correct_channel(self, voice_sync, _):
- """Test function sends messages to the correct channels."""
- text_channel = MockTextChannel()
- voice_channel = MockVoiceChannel()
- ctx = MockContext()
-
- test_cases = (
- (None, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
- (text_channel, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
- (voice_channel, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
- (ctx.channel, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
- )
-
- for target, message in test_cases:
- with self.subTest(target_channel=target, message=message):
- await self.cog.silence.callback(self.cog, ctx, 10, target, kick=False)
-
- if ctx.channel == target or target is None:
- ctx.channel.send.assert_called_once_with(message)
-
- else:
- ctx.channel.send.assert_called_once_with(message.replace("current channel", target.mention))
- if isinstance(target, MockTextChannel):
- target.send.assert_called_once_with(message)
- else:
- voice_sync.assert_called_once_with(target)
-
- ctx.channel.send.reset_mock()
- if target is not None and isinstance(target, MockTextChannel):
- target.send.reset_mock()
+ for target in [MockTextChannel(), MockVoiceChannel(), None]:
+ with self.subTest(was_silenced=was_silenced, target=target, message=message):
+ with mock.patch.object(self.cog, "send_message") as send_message:
+ ctx = MockContext()
+ await self.cog.silence.callback(self.cog, ctx, duration, target)
+ send_message.assert_called_once_with(
+ message,
+ ctx.channel,
+ target or ctx.channel,
+ alert_target=was_silenced
+ )
@voice_sync_helper
async def test_sync_called(self, ctx, sync, kick):