aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/cogs/test_information.py4
-rw-r--r--tests/bot/test_decorators.py60
2 files changed, 32 insertions, 32 deletions
diff --git a/tests/bot/cogs/test_information.py b/tests/bot/cogs/test_information.py
index 4a36fe030..6dace1080 100644
--- a/tests/bot/cogs/test_information.py
+++ b/tests/bot/cogs/test_information.py
@@ -7,7 +7,7 @@ import discord
from bot import constants
from bot.cogs import information
-from bot.decorators import InWhitelistedContextCheckFailure
+from bot.decorators import InWhitelistCheckFailure
from tests import helpers
@@ -525,7 +525,7 @@ class UserCommandTests(unittest.TestCase):
ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(id=100))
msg = "Sorry, but you may only use this command within <#50>."
- with self.assertRaises(InWhitelistedContextCheckFailure, msg=msg):
+ with self.assertRaises(InWhitelistCheckFailure, msg=msg):
asyncio.run(self.cog.user_info.callback(self.cog, ctx))
@unittest.mock.patch("bot.cogs.information.Information.create_user_embed", new_callable=unittest.mock.AsyncMock)
diff --git a/tests/bot/test_decorators.py b/tests/bot/test_decorators.py
index fae7c0c52..645051fec 100644
--- a/tests/bot/test_decorators.py
+++ b/tests/bot/test_decorators.py
@@ -2,15 +2,15 @@ import collections
import unittest
import unittest.mock
-from bot.decorators import InWhitelistedContextCheckFailure, in_whitelisted_context
+from bot.decorators import InWhitelistCheckFailure, in_whitelist
from tests import helpers
WhitelistedContextTestCase = collections.namedtuple("WhitelistedContextTestCase", ("kwargs", "ctx"))
-class InWhitelistedContextTests(unittest.TestCase):
- """Tests for the `in_whitelisted_context` check."""
+class InWhitelistTests(unittest.TestCase):
+ """Tests for the `in_whitelist` check."""
@classmethod
def setUpClass(cls):
@@ -23,43 +23,43 @@ class InWhitelistedContextTests(unittest.TestCase):
cls.staff_role = helpers.MockRole(id=121212)
cls.staff_member = helpers.MockMember(roles=(cls.staff_role,))
- cls.whitelisted_channels = (cls.bot_commands.id,)
- cls.whitelisted_categories = (cls.help_channel.category_id,)
- cls.whitelisted_roles = (cls.staff_role.id,)
+ cls.channels = (cls.bot_commands.id,)
+ cls.categories = (cls.help_channel.category_id,)
+ cls.roles = (cls.staff_role.id,)
def test_predicate_returns_true_for_whitelisted_context(self):
"""The predicate should return `True` if a whitelisted context was passed to it."""
test_cases = (
# Commands issued in whitelisted channels by members without whitelisted roles
WhitelistedContextTestCase(
- kwargs={"whitelisted_channels": self.whitelisted_channels},
+ kwargs={"channels": self.channels},
ctx=helpers.MockContext(channel=self.bot_commands, author=self.non_staff_member)
),
- # `redirect_channel` should be added implicitly to the `whitelisted_channels`
+ # `redirect` should be added implicitly to the `channels`
WhitelistedContextTestCase(
- kwargs={"redirect_channel": self.bot_commands.id},
+ kwargs={"redirect": self.bot_commands.id},
ctx=helpers.MockContext(channel=self.bot_commands, author=self.non_staff_member)
),
# Commands issued in a whitelisted category by members without whitelisted roles
WhitelistedContextTestCase(
- kwargs={"whitelisted_categories": self.whitelisted_categories},
+ kwargs={"categories": self.categories},
ctx=helpers.MockContext(channel=self.help_channel, author=self.non_staff_member)
),
# Command issued by a staff member in a non-whitelisted channel/category
WhitelistedContextTestCase(
- kwargs={"whitelisted_roles": self.whitelisted_roles},
+ kwargs={"roles": self.roles},
ctx=helpers.MockContext(channel=self.non_whitelisted_channel, author=self.staff_member)
),
# With all kwargs provided
WhitelistedContextTestCase(
kwargs={
- "whitelisted_channels": self.whitelisted_channels,
- "whitelisted_categories": self.whitelisted_categories,
- "whitelisted_roles": self.whitelisted_roles,
- "redirect_channel": self.bot_commands,
+ "channels": self.channels,
+ "categories": self.categories,
+ "roles": self.roles,
+ "redirect": self.bot_commands,
},
ctx=helpers.MockContext(channel=self.help_channel, author=self.staff_member)
),
@@ -69,31 +69,31 @@ class InWhitelistedContextTests(unittest.TestCase):
# patch `commands.check` with a no-op lambda that just returns the predicate passed to it
# so we can test the predicate that was generated from the specified kwargs.
with unittest.mock.patch("bot.decorators.commands.check", new=lambda predicate: predicate):
- predicate = in_whitelisted_context(**test_case.kwargs)
+ predicate = in_whitelist(**test_case.kwargs)
with self.subTest(test_case=test_case):
self.assertTrue(predicate(test_case.ctx))
def test_predicate_raises_exception_for_non_whitelisted_context(self):
- """The predicate should raise `InWhitelistedContextCheckFailure` for a non-whitelisted context."""
+ """The predicate should raise `InWhitelistCheckFailure` for a non-whitelisted context."""
test_cases = (
- # Failing check with `redirect_channel`
+ # Failing check with `redirect`
WhitelistedContextTestCase(
kwargs={
- "whitelisted_categories": self.whitelisted_categories,
- "whitelisted_channels": self.whitelisted_channels,
- "whitelisted_roles": self.whitelisted_roles,
- "redirect_channel": self.bot_commands.id,
+ "categories": self.categories,
+ "channels": self.channels,
+ "roles": self.roles,
+ "redirect": self.bot_commands.id,
},
ctx=helpers.MockContext(channel=self.non_whitelisted_channel, author=self.non_staff_member)
),
- # Failing check without `redirect_channel`
+ # Failing check without `redirect`
WhitelistedContextTestCase(
kwargs={
- "whitelisted_categories": self.whitelisted_categories,
- "whitelisted_channels": self.whitelisted_channels,
- "whitelisted_roles": self.whitelisted_roles,
+ "categories": self.categories,
+ "channels": self.channels,
+ "roles": self.roles,
},
ctx=helpers.MockContext(channel=self.non_whitelisted_channel, author=self.non_staff_member)
),
@@ -102,14 +102,14 @@ class InWhitelistedContextTests(unittest.TestCase):
for test_case in test_cases:
# Create expected exception message based on whether or not a redirect channel was provided
expected_message = "Sorry, but you are not allowed to use that command here."
- if test_case.kwargs.get("redirect_channel"):
- expected_message += f" Please use the <#{test_case.kwargs['redirect_channel']}> channel instead."
+ if test_case.kwargs.get("redirect"):
+ expected_message += f" Please use the <#{test_case.kwargs['redirect']}> channel instead."
# patch `commands.check` with a no-op lambda that just returns the predicate passed to it
# so we can test the predicate that was generated from the specified kwargs.
with unittest.mock.patch("bot.decorators.commands.check", new=lambda predicate: predicate):
- predicate = in_whitelisted_context(**test_case.kwargs)
+ predicate = in_whitelist(**test_case.kwargs)
with self.subTest(test_case=test_case):
- with self.assertRaises(InWhitelistedContextCheckFailure, msg=expected_message):
+ with self.assertRaises(InWhitelistCheckFailure, msg=expected_message):
predicate(test_case.ctx)