aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/exts/backend/test_security.py (renamed from tests/bot/exts/filters/test_security.py)2
-rw-r--r--tests/bot/exts/info/test_information.py24
-rw-r--r--tests/bot/exts/recruitment/talentpool/test_review.py39
3 files changed, 34 insertions, 31 deletions
diff --git a/tests/bot/exts/filters/test_security.py b/tests/bot/exts/backend/test_security.py
index 007b7b1eb..c3985c609 100644
--- a/tests/bot/exts/filters/test_security.py
+++ b/tests/bot/exts/backend/test_security.py
@@ -2,7 +2,7 @@ import unittest
from discord.ext.commands import NoPrivateMessage
-from bot.exts.filters import security
+from bot.exts.backend import security
from tests.helpers import MockBot, MockContext
diff --git a/tests/bot/exts/info/test_information.py b/tests/bot/exts/info/test_information.py
index 9f5143c01..65595e959 100644
--- a/tests/bot/exts/info/test_information.py
+++ b/tests/bot/exts/info/test_information.py
@@ -603,9 +603,9 @@ class RuleCommandTests(unittest.IsolatedAsyncioTestCase):
async def test_return_none_if_one_rule_number_is_invalid(self):
test_cases = [
- (('1', '6', '7', '8'), (6, 7, 8)),
- (('10', "first"), (10, )),
- (("first", 10), (10, ))
+ ("1 6 7 8", (6, 7, 8)),
+ ("10 first", (10,)),
+ ("first 10", (10,))
]
for raw_user_input, extracted_rule_numbers in test_cases:
@@ -614,7 +614,7 @@ class RuleCommandTests(unittest.IsolatedAsyncioTestCase):
str(rule_number) for rule_number in extracted_rule_numbers
if rule_number < 1 or rule_number > len(self.full_rules))
- final_rule_numbers = await self.cog.rules(self.cog, self.ctx, *raw_user_input)
+ final_rule_numbers = await self.cog.rules(self.cog, self.ctx, args=raw_user_input)
self.assertEqual(
self.ctx.send.call_args,
@@ -624,26 +624,26 @@ class RuleCommandTests(unittest.IsolatedAsyncioTestCase):
async def test_return_correct_rule_numbers(self):
test_cases = [
- (("1", "2", "first"), {1, 2}),
- (("1", "hello", "2", "second"), {1}),
- (("second", "third", "unknown", "999"), {2, 3})
+ ("1 2 first", {1, 2}),
+ ("1 hello 2 second", {1}),
+ ("second third unknown 999", {2, 3}),
]
for raw_user_input, expected_matched_rule_numbers in test_cases:
with self.subTest(identifier=raw_user_input):
- final_rule_numbers = await self.cog.rules(self.cog, self.ctx, *raw_user_input)
+ final_rule_numbers = await self.cog.rules(self.cog, self.ctx, args=raw_user_input)
self.assertEqual(expected_matched_rule_numbers, final_rule_numbers)
async def test_return_default_rules_when_no_input_or_no_match_are_found(self):
test_cases = [
- ((), None),
- (("hello", "2", "second"), None),
- (("hello", "999"), None),
+ ("", None),
+ ("hello 2 second", None),
+ ("hello 999", None),
]
for raw_user_input, expected_matched_rule_numbers in test_cases:
with self.subTest(identifier=raw_user_input):
- final_rule_numbers = await self.cog.rules(self.cog, self.ctx, *raw_user_input)
+ final_rule_numbers = await self.cog.rules(self.cog, self.ctx, args=raw_user_input)
embed = self.ctx.send.call_args.kwargs['embed']
self.assertEqual(information.DEFAULT_RULES_DESCRIPTION, embed.description)
self.assertEqual(expected_matched_rule_numbers, final_rule_numbers)
diff --git a/tests/bot/exts/recruitment/talentpool/test_review.py b/tests/bot/exts/recruitment/talentpool/test_review.py
index 295b0e221..1ddb73ab0 100644
--- a/tests/bot/exts/recruitment/talentpool/test_review.py
+++ b/tests/bot/exts/recruitment/talentpool/test_review.py
@@ -31,10 +31,12 @@ def nomination(
num_entries: int,
reviewed: bool = False,
id: int | None = None
-) -> tuple[int, dict]:
- return (
- id or MockMember().id,
- {"inserted_at": inserted_at.isoformat(), "entries": [Mock() for _ in range(num_entries)], "reviewed": reviewed},
+) -> Mock:
+ return Mock(
+ id=id or MockMember().id,
+ inserted_at=inserted_at,
+ entries=[Mock() for _ in range(num_entries)],
+ reviewed=reviewed
)
@@ -48,8 +50,8 @@ class ReviewerTests(unittest.IsolatedAsyncioTestCase):
self.voting_channel = MockTextChannel()
self.bot.get_channel = Mock(return_value=self.voting_channel)
- self.pool = Mock(name="MockTalentPool")
- self.reviewer = _review.Reviewer(self.bot, self.pool)
+ self.nomination_api = Mock(name="MockNominationAPI")
+ self.reviewer = _review.Reviewer(self.bot, self.nomination_api)
@patch("bot.exts.recruitment.talentpool._review.MAX_ONGOING_REVIEWS", 3)
@patch("bot.exts.recruitment.talentpool._review.MIN_REVIEW_INTERVAL", timedelta(days=1))
@@ -118,8 +120,8 @@ class ReviewerTests(unittest.IsolatedAsyncioTestCase):
cache_get_mock.assert_called_with("last_vote_date")
@patch("bot.exts.recruitment.talentpool._review.MIN_NOMINATION_TIME", timedelta(days=7))
- async def test_get_user_for_review(self):
- """Test get_user_for_review function."""
+ async def test_get_nomination_to_review(self):
+ """Test get_nomination_to_review function."""
now = datetime.now(timezone.utc)
# Each case contains a list of nominations, followed by the index in that list
@@ -156,19 +158,19 @@ class ReviewerTests(unittest.IsolatedAsyncioTestCase):
]
for (case_num, (nominations, expected)) in enumerate(cases, 1):
- nomination_dict = dict(nominations)
-
with self.subTest(case_num=case_num):
- self.pool.cache = nomination_dict
- res = await self.reviewer.get_user_for_review()
+ get_nominations_mock = AsyncMock(return_value=nominations)
+ self.nomination_api.get_nominations = get_nominations_mock
+ res = await self.reviewer.get_nomination_to_review()
if expected is None:
self.assertIsNone(res)
else:
- self.assertEqual(res, nominations[expected][0])
+ self.assertEqual(res, nominations[expected])
+ get_nominations_mock.assert_called_once_with(active=True)
@patch("bot.exts.recruitment.talentpool._review.MIN_NOMINATION_TIME", timedelta(days=0))
- async def test_get_user_for_review_order(self):
+ async def test_get_nomination_to_review_order(self):
now = datetime.now(timezone.utc)
# Each case in cases is a list of nominations in the order they should be chosen from first to last
@@ -206,8 +208,9 @@ class ReviewerTests(unittest.IsolatedAsyncioTestCase):
with self.subTest(case_num=case_num):
for i in range(len(case)):
with self.subTest(nomination_num=i+1):
- sub_case = dict(case[i:])
- self.pool.cache = sub_case
+ get_nominations_mock = AsyncMock(return_value=case[i:])
+ self.nomination_api.get_nominations = get_nominations_mock
- res = await self.reviewer.get_user_for_review()
- self.assertEqual(res, case[i][0])
+ res = await self.reviewer.get_nomination_to_review()
+ self.assertEqual(res, case[i])
+ get_nominations_mock.assert_called_once_with(active=True)