diff options
| author | 2020-03-11 02:58:09 +0100 | |
|---|---|---|
| committer | 2020-03-11 02:58:09 +0100 | |
| commit | c72d31f717ac5e755fe3848c99ebf426fcdf6d8b (patch) | |
| tree | 03acda0b93e8611bcc71f5e79108bc19fa01cb6f /tests | |
| parent | Separate tests for permissions and `muted_channels.add` on `_silence`. (diff) | |
Use patch decorators and assign names from `with` patches.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bot/cogs/moderation/test_silence.py | 22 | 
1 files changed, 11 insertions, 11 deletions
diff --git a/tests/bot/cogs/moderation/test_silence.py b/tests/bot/cogs/moderation/test_silence.py index 3a513f3a7..027508661 100644 --- a/tests/bot/cogs/moderation/test_silence.py +++ b/tests/bot/cogs/moderation/test_silence.py @@ -99,28 +99,28 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):          self.assertFalse(await self.cog._unsilence(channel))          channel.set_permissions.assert_not_called() -    async def test_unsilence_private_unsilenced_channel(self): +    @mock.patch.object(Silence, "notifier", create=True) +    async def test_unsilence_private_unsilenced_channel(self, _):          """Channel had `send_message` permissions restored"""          perm_overwrite = MagicMock(send_messages=False)          channel = MockTextChannel(overwrites_for=Mock(return_value=perm_overwrite)) -        with mock.patch.object(self.cog, "notifier", create=True): -            self.assertTrue(await self.cog._unsilence(channel)) +        self.assertTrue(await self.cog._unsilence(channel))          channel.set_permissions.assert_called_once()          self.assertTrue(channel.set_permissions.call_args.kwargs['overwrite'].send_messages) -    async def test_unsilence_private_removed_notifier(self): +    @mock.patch.object(Silence, "notifier", create=True) +    async def test_unsilence_private_removed_notifier(self, notifier):          """Channel was removed from `notifier` on unsilence."""          perm_overwrite = MagicMock(send_messages=False)          channel = MockTextChannel(overwrites_for=Mock(return_value=perm_overwrite)) -        with mock.patch.object(self.cog, "notifier", create=True): -            await self.cog._unsilence(channel) -            self.cog.notifier.remove_channel.call_args.assert_called_once_with(channel) +        await self.cog._unsilence(channel) +        notifier.remove_channel.call_args.assert_called_once_with(channel) -    async def test_unsilence_private_removed_muted_channel(self): +    @mock.patch.object(Silence, "notifier", create=True) +    async def test_unsilence_private_removed_muted_channel(self, _):          """Channel was removed from `muted_channels` on unsilence."""          perm_overwrite = MagicMock(send_messages=False)          channel = MockTextChannel(overwrites_for=Mock(return_value=perm_overwrite)) -        with mock.patch.object(self.cog, "muted_channels", create=True),\ -             mock.patch.object(self.cog, "notifier", create=True):  # noqa E127 +        with mock.patch.object(self.cog, "muted_channels") as muted_channels:              await self.cog._unsilence(channel) -            self.cog.muted_channels.remove.call_args.assert_called_once_with(channel) +        muted_channels.remove.call_args.assert_called_once_with(channel)  |