diff options
author | 2020-06-13 17:24:31 +0200 | |
---|---|---|
committer | 2020-06-13 17:55:32 +0200 | |
commit | c66b4a618503352803f73e9272a1d27b6e0a4d52 (patch) | |
tree | d23e7207566b308cdc10ff7d3896a77b4ee1182b | |
parent | Incidents tests: improve mock `Signal` name & move def (diff) |
Incidents tests: set up base class for `Incidents`
For cleanliness, I've decided to make a separate class for each method.
Since most tests will want to have an `Incident` instance ready, they
can inherit the `setUp` from `TestIncidents`, which does not make any
assertions on its own.
-rw-r--r-- | tests/bot/cogs/moderation/test_incidents.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/bot/cogs/moderation/test_incidents.py b/tests/bot/cogs/moderation/test_incidents.py index a349c1cb7..d52932e0a 100644 --- a/tests/bot/cogs/moderation/test_incidents.py +++ b/tests/bot/cogs/moderation/test_incidents.py @@ -2,8 +2,8 @@ import enum import unittest from unittest.mock import MagicMock, call, patch -from bot.cogs.moderation import incidents -from tests.helpers import MockMessage, MockReaction, MockTextChannel, MockUser +from bot.cogs.moderation import Incidents, incidents +from tests.helpers import MockBot, MockMessage, MockReaction, MockTextChannel, MockUser class MockSignal(enum.Enum): @@ -131,3 +131,22 @@ class TestAddSignals(unittest.IsolatedAsyncioTestCase): """No emoji are added when all are present.""" await incidents.add_signals(self.incident) self.incident.add_reaction.assert_not_called() + + +class TestIncidents(unittest.IsolatedAsyncioTestCase): + """ + Tests for bound methods of the `Incidents` cog. + + Use this as a base class for `Incidents` tests - it will prepare a fresh instance + for each test function, but not make any assertions on its own. Tests can mutate + the instance as they wish. + """ + + def setUp(self): + """ + Prepare a fresh `Incidents` instance for each test. + + Note that this will not schedule `crawl_incidents` in the background, as everything + is being mocked. The `crawl_task` attribute will end up being None. + """ + self.cog_instance = Incidents(MockBot()) |