Ensure backwards compatibility when fetching a redis client

This commit is contained in:
Erik Kalkoken
2022-07-07 07:37:21 +00:00
committed by Ariel Rin
parent 113977b19f
commit 8dec242a93
12 changed files with 94 additions and 33 deletions

View File

@@ -5,7 +5,7 @@ from typing import List, Optional
from pytz import utc
from redis import Redis, RedisError
from django.core.cache import cache
from allianceauth.utils.cache import get_redis_client
logger = logging.getLogger(__name__)
@@ -39,7 +39,7 @@ class EventSeries:
_ROOT_KEY = "ALLIANCEAUTH_EVENT_SERIES"
def __init__(self, key_id: str, redis: Redis = None) -> None:
self._redis = cache.get_master_client() if not redis else redis
self._redis = get_redis_client() if not redis else redis
try:
if not self._redis.ping():
raise RuntimeError()

View File

@@ -18,7 +18,7 @@ MODULE_PATH = "allianceauth.authentication.task_statistics.event_series"
class TestEventSeries(TestCase):
def test_should_abort_without_redis_client(self):
# when
with patch(MODULE_PATH + ".cache.get_master_client") as mock:
with patch(MODULE_PATH + ".get_redis_client") as mock:
mock.return_value = None
events = EventSeries("dummy")
# then
@@ -27,7 +27,7 @@ class TestEventSeries(TestCase):
def test_should_disable_itself_if_redis_not_available_1(self):
# when
with patch(MODULE_PATH + ".cache.get_master_client") as mock_get_master_client:
with patch(MODULE_PATH + ".get_redis_client") as mock_get_master_client:
mock_get_master_client.return_value.ping.side_effect = RedisError
events = EventSeries("dummy")
# then
@@ -36,7 +36,7 @@ class TestEventSeries(TestCase):
def test_should_disable_itself_if_redis_not_available_2(self):
# when
with patch(MODULE_PATH + ".cache.get_master_client") as mock_get_master_client:
with patch(MODULE_PATH + ".get_redis_client") as mock_get_master_client:
mock_get_master_client.return_value.ping.return_value = False
events = EventSeries("dummy")
# then