aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-10-08 13:23:35 -0700
committerGravatar MarkKoz <[email protected]>2020-10-08 13:23:35 -0700
commite85a4d254cadd303537a4d2cce6637bbcd3cf2f9 (patch)
treef4ce6c57b5efe3b386f942bd59f343a288b0351f
parentSilence: remove _mod_log_channel attribute (diff)
Silence tests: make _async_init attribute tests more robust
-rw-r--r--tests/bot/cogs/moderation/test_silence.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/tests/bot/cogs/moderation/test_silence.py b/tests/bot/cogs/moderation/test_silence.py
index 6f8f4386b..3e1b963b0 100644
--- a/tests/bot/cogs/moderation/test_silence.py
+++ b/tests/bot/cogs/moderation/test_silence.py
@@ -102,24 +102,28 @@ class SilenceCogTests(unittest.IsolatedAsyncioTestCase):
@autospec(silence, "SilenceNotifier", pass_mocks=False)
async def test_async_init_got_role(self):
"""Got `Roles.verified` role from guild."""
- await self.cog._async_init()
guild = self.bot.get_guild()
- guild.get_role.assert_called_once_with(Roles.verified)
+ guild.get_role.side_effect = lambda id_: Mock(id=id_)
+
+ await self.cog._async_init()
+ self.assertEqual(self.cog._verified_role.id, Roles.verified)
@autospec(silence, "SilenceNotifier", pass_mocks=False)
async def test_async_init_got_channels(self):
"""Got channels from bot."""
+ self.bot.get_channel.side_effect = lambda id_: MockTextChannel(id=id_)
+
await self.cog._async_init()
- self.bot.get_channel.called_once_with(Channels.mod_alerts)
- self.bot.get_channel.called_once_with(Channels.mod_log)
+ self.assertEqual(self.cog._mod_alerts_channel.id, Channels.mod_alerts)
@autospec(silence, "SilenceNotifier")
async def test_async_init_got_notifier(self, notifier):
"""Notifier was started with channel."""
- mod_log = MockTextChannel()
- self.bot.get_channel.side_effect = (None, mod_log)
+ self.bot.get_channel.side_effect = lambda id_: MockTextChannel(id=id_)
+
await self.cog._async_init()
- notifier.assert_called_once_with(mod_log)
+ notifier.assert_called_once_with(MockTextChannel(id=Channels.mod_log))
+ self.assertEqual(self.cog.notifier, notifier.return_value)
@autospec(silence, "SilenceNotifier", pass_mocks=False)
async def test_async_init_rescheduled(self):