aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-05-10 15:09:22 -0700
committerGravatar MarkKoz <[email protected]>2020-05-11 12:03:11 -0700
commitb0dd290710799c342240d066abaebbe9e6940b54 (patch)
tree323283f95a3b6cf3e65c105b56d461b89b52dae9
parentAllow using arbitrary parameter names with the autospec decorator (diff)
Fix test for token remover ignoring bot messages
It's not possible to test this via asserting the return value of `on_message` since it never returns anything. Instead, the actual relevant unit, `find_token_in_message,` should be tested.
-rw-r--r--tests/bot/cogs/test_token_remover.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/bot/cogs/test_token_remover.py b/tests/bot/cogs/test_token_remover.py
index 2b377e221..e8b641101 100644
--- a/tests/bot/cogs/test_token_remover.py
+++ b/tests/bot/cogs/test_token_remover.py
@@ -89,11 +89,16 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
find_token_in_message.assert_called_once_with(self.msg)
take_action.assert_not_awaited()
- def test_ignores_bot_messages(self):
- """When the message event handler is called with a bot message, nothing is done."""
+ @autospec("bot.cogs.token_remover", "TOKEN_RE")
+ def test_find_token_ignores_bot_messages(self, token_re):
+ """The token finder should ignore messages authored by bots."""
+ cog = TokenRemover(self.bot)
self.msg.author.bot = True
- coroutine = self.cog.on_message(self.msg)
- self.assertIsNone(asyncio.run(coroutine))
+
+ return_value = cog.find_token_in_message(self.msg)
+
+ self.assertIsNone(return_value)
+ token_re.findall.assert_not_called()
def test_ignores_messages_without_tokens(self):
"""Messages without anything looking like a token are ignored."""