summaryrefslogtreecommitdiff
path: root/tests/test_helpers.py
diff options
context:
space:
mode:
authorJoachim Burket <joachimBurket@users.noreply.github.com>2023-03-07 04:03:31 +0100
committerGitHub <noreply@github.com>2023-03-07 10:03:31 +0700
commit7f9f0f72ba1adac907791d604d5f56af8125fdfd (patch)
treed6977cfafac350140c2cb5c66b7585756c497b01 /tests/test_helpers.py
parent82a59e9791335fcdd263fda2799aa126ddce4e90 (diff)
downloadrq-7f9f0f72ba1adac907791d604d5f56af8125fdfd.tar.gz
Update arguments passed to the Sentinel Object when created from the settings (#1850)
* Updated arguments passed to the Sentinel Object when created from the settings - added `USERNAME` key - added `CONNECTION_KWARGS` key to allow passing additionals arguments to the Redis connections - updated the documentation * added missing comma * tests(helpers): Added tests for Sentinel --------- Co-authored-by: Joachim Burket <joachim.burket@hopitalvs.ch>
Diffstat (limited to 'tests/test_helpers.py')
-rw-r--r--tests/test_helpers.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index b43f13b..5a84f71 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -1,11 +1,12 @@
from rq.cli.helpers import get_redis_from_config
from tests import RQTestCase
-
+from unittest import mock
class TestHelpers(RQTestCase):
- def test_get_redis_from_config(self):
+ @mock.patch('rq.cli.helpers.Sentinel')
+ def test_get_redis_from_config(self, sentinel_class_mock):
"""Ensure Redis connection params are properly parsed"""
settings = {
'REDIS_URL': 'redis://localhost:1/1'
@@ -39,3 +40,46 @@ class TestHelpers(RQTestCase):
self.assertEqual(connection_kwargs['db'], 2)
self.assertEqual(connection_kwargs['port'], 2)
self.assertEqual(connection_kwargs['password'], 'bar')
+
+ # Add Sentinel to the settings
+ settings.update({
+ 'SENTINEL': {
+ 'INSTANCES':[('remote.host1.org', 26379), ('remote.host2.org', 26379), ('remote.host3.org', 26379)],
+ 'MASTER_NAME': 'master',
+ 'DB': 2,
+ 'USERNAME': 'redis-user',
+ 'PASSWORD': 'redis-secret',
+ 'SOCKET_TIMEOUT': None,
+ 'CONNECTION_KWARGS': {
+ 'ssl_ca_path': None,
+ },
+ 'SENTINEL_KWARGS': {
+ 'username': 'sentinel-user',
+ 'password': 'sentinel-secret',
+ },
+ },
+ })
+
+ # Ensure SENTINEL is preferred against REDIS_* parameters
+ redis = get_redis_from_config(settings)
+ sentinel_init_sentinels_args = sentinel_class_mock.call_args[0]
+ sentinel_init_sentinel_kwargs = sentinel_class_mock.call_args[1]
+ self.assertEqual(
+ sentinel_init_sentinels_args,
+ ([('remote.host1.org', 26379), ('remote.host2.org', 26379), ('remote.host3.org', 26379)],)
+ )
+ self.assertDictEqual(
+ sentinel_init_sentinel_kwargs,
+ {
+ 'db': 2,
+ 'ssl': False,
+ 'username': 'redis-user',
+ 'password': 'redis-secret',
+ 'socket_timeout': None,
+ 'ssl_ca_path': None,
+ 'sentinel_kwargs': {
+ 'username': 'sentinel-user',
+ 'password': 'sentinel-secret',
+ }
+ }
+ )