diff options
author | 2020-09-06 09:14:11 -0700 | |
---|---|---|
committer | 2020-09-08 10:15:36 -0700 | |
commit | 7741e9fd9054cb302e2d65afc8303db01c8eed7e (patch) | |
tree | 0006a592b992baf2a0fc01be77af9812896bf422 /tests | |
parent | Rename role checks and decorators (diff) |
Fix tests for has_any_role_check
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bot/utils/test_checks.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/tests/bot/utils/test_checks.py b/tests/bot/utils/test_checks.py index dfee2cf91..883465e0b 100644 --- a/tests/bot/utils/test_checks.py +++ b/tests/bot/utils/test_checks.py @@ -1,48 +1,50 @@ import unittest from unittest.mock import MagicMock +from discord import DMChannel + from bot.utils import checks from bot.utils.checks import InWhitelistCheckFailure from tests.helpers import MockContext, MockRole -class ChecksTests(unittest.TestCase): +class ChecksTests(unittest.IsolatedAsyncioTestCase): """Tests the check functions defined in `bot.checks`.""" def setUp(self): self.ctx = MockContext() - def test_has_any_role_check_without_guild(self): - """`has_any_role_check` returns `False` if `Context.guild` is None.""" - self.ctx.guild = None - self.assertFalse(checks.has_any_role_check(self.ctx)) + async def test_has_any_role_check_without_guild(self): + """`has_any_role_check` returns `False` for non-guild channels.""" + self.ctx.channel = MagicMock(DMChannel) + self.assertFalse(await checks.has_any_role_check(self.ctx)) - def test_has_any_role_check_without_required_roles(self): + async def test_has_any_role_check_without_required_roles(self): """`has_any_role_check` returns `False` if `Context.author` lacks the required role.""" self.ctx.author.roles = [] - self.assertFalse(checks.has_any_role_check(self.ctx)) + self.assertFalse(await checks.has_any_role_check(self.ctx)) - def test_has_any_role_check_with_guild_and_required_role(self): + async def test_has_any_role_check_with_guild_and_required_role(self): """`has_any_role_check` returns `True` if `Context.author` has the required role.""" self.ctx.author.roles.append(MockRole(id=10)) - self.assertTrue(checks.has_any_role_check(self.ctx, 10)) + self.assertTrue(await checks.has_any_role_check(self.ctx, 10)) - def test_has_no_roles_check_without_guild(self): + async def test_has_no_roles_check_without_guild(self): """`has_no_roles_check` should return `False` when `Context.guild` is None.""" - self.ctx.guild = None - self.assertFalse(checks.has_no_roles_check(self.ctx)) + self.ctx.channel = MagicMock(DMChannel) + self.assertFalse(await checks.has_no_roles_check(self.ctx)) - def test_has_no_roles_check_returns_false_with_unwanted_role(self): + async def test_has_no_roles_check_returns_false_with_unwanted_role(self): """`has_no_roles_check` returns `False` if `Context.author` has unwanted role.""" role_id = 42 self.ctx.author.roles.append(MockRole(id=role_id)) - self.assertFalse(checks.has_no_roles_check(self.ctx, role_id)) + self.assertFalse(await checks.has_no_roles_check(self.ctx, role_id)) - def test_has_no_roles_check_returns_true_without_unwanted_role(self): + async def test_has_no_roles_check_returns_true_without_unwanted_role(self): """`has_no_roles_check` returns `True` if `Context.author` does not have unwanted role.""" role_id = 42 self.ctx.author.roles.append(MockRole(id=role_id)) - self.assertTrue(checks.has_no_roles_check(self.ctx, role_id + 10)) + self.assertTrue(await checks.has_no_roles_check(self.ctx, role_id + 10)) def test_in_whitelist_check_correct_channel(self): """`in_whitelist_check` returns `True` if `Context.channel.id` is in the channel list.""" |