summaryrefslogtreecommitdiff
path: root/tests/test_helpers.py
diff options
context:
space:
mode:
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',
+ }
+ }
+ )