diff options
| author | 2022-07-30 19:29:27 +0100 | |
|---|---|---|
| committer | 2022-08-14 19:43:54 +0100 | |
| commit | f044f36833e9dc003e89dd81868ea3f48a9da002 (patch) | |
| tree | 92dc92de232e13f19f9feed2996122938fb944e1 | |
| parent | Add a new test helper for managing redis sessions (diff) | |
Use RedisTestCase helper class for both Incidents and Silence test cases.
| -rw-r--r-- | tests/bot/exts/moderation/test_incidents.py | 19 | ||||
| -rw-r--r-- | tests/bot/exts/moderation/test_silence.py | 23 | 
2 files changed, 6 insertions, 36 deletions
| diff --git a/tests/bot/exts/moderation/test_incidents.py b/tests/bot/exts/moderation/test_incidents.py index 211eb1bf8..97682163f 100644 --- a/tests/bot/exts/moderation/test_incidents.py +++ b/tests/bot/exts/moderation/test_incidents.py @@ -8,11 +8,11 @@ from unittest.mock import AsyncMock, MagicMock, Mock, call, patch  import aiohttp  import discord -from async_rediscache import RedisSession  from bot.constants import Colours  from bot.exts.moderation import incidents  from bot.utils.messages import format_user +from tests.base import RedisTestCase  from tests.helpers import (      MockAsyncWebhook, MockAttachment, MockBot, MockMember, MockMessage, MockReaction, MockRole, MockTextChannel,      MockUser @@ -270,7 +270,7 @@ class TestAddSignals(unittest.IsolatedAsyncioTestCase):          self.incident.add_reaction.assert_not_called() -class TestIncidents(unittest.IsolatedAsyncioTestCase): +class TestIncidents(RedisTestCase):      """      Tests for bound methods of the `Incidents` cog. @@ -279,21 +279,6 @@ class TestIncidents(unittest.IsolatedAsyncioTestCase):      the instance as they wish.      """ -    session = None - -    async def flush(self): -        """Flush everything from the database to prevent carry-overs between tests.""" -        await self.session.client.flushall() - -    async def asyncSetUp(self): -        self.session = RedisSession(use_fakeredis=True) -        await self.session.connect() -        await self.flush() - -    async def asyncTearDown(self): -        if self.session: -            await self.session.client.close() -      def setUp(self):          """          Prepare a fresh `Incidents` instance for each test. diff --git a/tests/bot/exts/moderation/test_silence.py b/tests/bot/exts/moderation/test_silence.py index f5caefdca..98547e2bc 100644 --- a/tests/bot/exts/moderation/test_silence.py +++ b/tests/bot/exts/moderation/test_silence.py @@ -6,30 +6,15 @@ from typing import List, Tuple  from unittest import mock  from unittest.mock import AsyncMock, Mock -from async_rediscache import RedisSession  from discord import PermissionOverwrite  from bot.constants import Channels, Guild, MODERATION_ROLES, Roles  from bot.exts.moderation import silence +from tests.base import RedisTestCase  from tests.helpers import (      MockBot, MockContext, MockGuild, MockMember, MockRole, MockTextChannel, MockVoiceChannel, autospec  ) -redis_session = None - - -def setUpModule(): -    """Create and connect to the fakeredis session.""" -    global redis_session -    redis_session = RedisSession(use_fakeredis=True) -    asyncio.run(redis_session.connect()) - - -def tearDownModule(): -    """Close the fakeredis session.""" -    if redis_session: -        asyncio.run(redis_session.client.close()) -  # Have to subclass it because builtins can't be patched.  class PatchedDatetime(datetime): @@ -104,7 +89,7 @@ class SilenceNotifierTests(unittest.IsolatedAsyncioTestCase):  @autospec(silence.Silence, "previous_overwrites", "unsilence_timestamps", pass_mocks=False) -class SilenceCogTests(unittest.IsolatedAsyncioTestCase): +class SilenceCogTests(RedisTestCase):      """Tests for the general functionality of the Silence cog."""      @autospec(silence, "Scheduler", pass_mocks=False) @@ -244,7 +229,7 @@ class SilenceCogTests(unittest.IsolatedAsyncioTestCase):              self.assertEqual(member.move_to.call_count, 1 if member == failing_member else 2) -class SilenceArgumentParserTests(unittest.IsolatedAsyncioTestCase): +class SilenceArgumentParserTests(RedisTestCase):      """Tests for the silence argument parser utility function."""      def setUp(self): @@ -403,7 +388,7 @@ def voice_sync_helper(function):  @autospec(silence.Silence, "previous_overwrites", "unsilence_timestamps", pass_mocks=False) -class SilenceTests(unittest.IsolatedAsyncioTestCase): +class SilenceTests(RedisTestCase):      """Tests for the silence command and its related helper methods."""      @autospec(silence.Silence, "_reschedule", pass_mocks=False) | 
