From 4e701453cf23486244759aae9769ad951a2b3cf2 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 28 Mar 2025 23:45:20 +0000 Subject: [PATCH] more unit tests --- src/socketio/redis_manager.py | 7 ++----- tests/common/test_redis_manager.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/socketio/redis_manager.py b/src/socketio/redis_manager.py index dabe6a0..df98618 100644 --- a/src/socketio/redis_manager.py +++ b/src/socketio/redis_manager.py @@ -29,15 +29,12 @@ def parse_redis_sentinel_url(url): kwargs['username'] = parsed_url.username if parsed_url.password: kwargs['password'] = parsed_url.password - if parsed_url.query: - for key, value in urlparse.parse_qs(parsed_url.query).items(): - kwargs[key] = value[0] service_name = None if parsed_url.path: parts = parsed_url.path.split('/') - if len(parts) >= 2: + if len(parts) >= 2 and parts[1] != '': kwargs['db'] = int(parts[1]) - if len(parts) >= 3: + if len(parts) >= 3 and parts[2] != '': service_name = parts[2] return sentinels, service_name, kwargs diff --git a/tests/common/test_redis_manager.py b/tests/common/test_redis_manager.py index 3dad58b..3e5ee1e 100644 --- a/tests/common/test_redis_manager.py +++ b/tests/common/test_redis_manager.py @@ -9,12 +9,26 @@ class TestPubSubManager: parse_redis_sentinel_url('redis://localhost:6379/0') assert parse_redis_sentinel_url( - 'redis+sentinel://h1:6379,h2:6379' + 'redis+sentinel://localhost:6379' ) == ( - [('h1', 6379), ('h2', 6379)], + [('localhost', 6379)], + None, + {} + ) + assert parse_redis_sentinel_url( + 'redis+sentinel://192.168.0.1:6379,192.168.0.2:6379/' + ) == ( + [('192.168.0.1', 6379), ('192.168.0.2', 6379)], None, {} ) + assert parse_redis_sentinel_url( + 'redis+sentinel://h1:6379,h2:6379/0' + ) == ( + [('h1', 6379), ('h2', 6379)], + None, + {'db': 0} + ) assert parse_redis_sentinel_url( 'redis+sentinel://user:password@h1:6379,h2:6379,h1:6380/0/myredis' ) == (