aboutsummaryrefslogtreecommitdiffstats
path: root/tests/base.py
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2022-09-24 16:00:41 +0300
committerGravatar mbaruh <[email protected]>2022-09-24 16:00:41 +0300
commit8c2ed9b61d8b80a521122e7bbe095c3211725744 (patch)
tree20f8e958486e86b4d5fe789c7637e5784f6b5531 /tests/base.py
parentConvert all setting entries to pydnatic models (diff)
parentMerge pull request #2232 from python-discord/bot-2231-enhancements (diff)
Merge branch 'main' into new-filters
Diffstat (limited to 'tests/base.py')
-rw-r--r--tests/base.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/base.py b/tests/base.py
index 5e304ea9d..4863a1821 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -4,6 +4,7 @@ from contextlib import contextmanager
from typing import Dict
import discord
+from async_rediscache import RedisSession
from discord.ext import commands
from bot.log import get_logger
@@ -104,3 +105,26 @@ class CommandTestCase(unittest.IsolatedAsyncioTestCase):
await cmd.can_run(ctx)
self.assertCountEqual(permissions.keys(), cm.exception.missing_permissions)
+
+
+class RedisTestCase(unittest.IsolatedAsyncioTestCase):
+ """
+ Use this as a base class for any test cases that require a redis session.
+
+ This will prepare a fresh redis instance for each test function, and will
+ not make any assertions on its own. Tests can mutate the instance as they wish.
+ """
+
+ session = None
+
+ async def flush(self):
+ """Flush everything from the redis database to prevent carry-overs between tests."""
+ await self.session.client.flushall()
+
+ async def asyncSetUp(self):
+ self.session = await RedisSession(use_fakeredis=True).connect()
+ await self.flush()
+
+ async def asyncTearDown(self):
+ if self.session:
+ await self.session.client.close()