aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2019-11-13 22:48:59 +0100
committerGravatar kwzrd <[email protected]>2019-11-13 22:48:59 +0100
commitdd098d91e35c2e333af14919d7405fe47f298ac2 (patch)
tree4142fd1ed5046f50b5507487c4bf6d0160f0fe1e
parentAdjust attachments rule to use MockMessage, restructure test cases (diff)
Use async_test helper to simplify coro testing
-rw-r--r--tests/bot/rules/test_attachments.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/bot/rules/test_attachments.py b/tests/bot/rules/test_attachments.py
index 2f8294922..770dd3201 100644
--- a/tests/bot/rules/test_attachments.py
+++ b/tests/bot/rules/test_attachments.py
@@ -1,8 +1,7 @@
-import asyncio
import unittest
from bot.rules import attachments
-from tests.helpers import MockMessage
+from tests.helpers import MockMessage, async_test
def msg(total_attachments: int) -> MockMessage:
@@ -13,7 +12,8 @@ def msg(total_attachments: int) -> MockMessage:
class AttachmentRuleTests(unittest.TestCase):
"""Tests applying the `attachments` antispam rule."""
- def test_allows_messages_without_too_many_attachments(self):
+ @async_test
+ async def test_allows_messages_without_too_many_attachments(self):
"""Messages without too many attachments are allowed as-is."""
cases = (
(msg(0), msg(0), msg(0)),
@@ -22,17 +22,23 @@ class AttachmentRuleTests(unittest.TestCase):
)
for last_message, *recent_messages in cases:
- with self.subTest(last_message=last_message, recent_messages=recent_messages):
- coro = attachments.apply(last_message, recent_messages, {'max': 5})
- self.assertIsNone(asyncio.run(coro))
+ with self.subTest(
+ last_message=last_message,
+ recent_messages=recent_messages
+ ):
+ self.assertIsNone(
+ await attachments.apply(last_message, recent_messages, {'max': 5})
+ )
- def test_disallows_messages_with_too_many_attachments(self):
+ @async_test
+ async def test_disallows_messages_with_too_many_attachments(self):
"""Messages with too many attachments trigger the rule."""
cases = (
([msg(4), msg(0), msg(6)], 10),
([msg(6)], 6),
([msg(1)] * 6, 6),
)
+
for messages, total in cases:
last_message, *recent_messages = messages
relevant_messages = [last_message] + [
@@ -48,8 +54,7 @@ class AttachmentRuleTests(unittest.TestCase):
relevant_messages=relevant_messages,
total=total
):
- coro = attachments.apply(last_message, recent_messages, {'max': 5})
self.assertEqual(
- asyncio.run(coro),
+ await attachments.apply(last_message, recent_messages, {'max': 5}),
(f"sent {total} attachments in 5s", ('lemon',), relevant_messages)
)