From e780ff3e73d78fccbc1c8cf0fbddcf99597cd6ff Mon Sep 17 00:00:00 2001 From: vcidst Date: Wed, 20 Sep 2023 14:20:05 +0200 Subject: [PATCH] add tests and username in RedisTrackerStore --- changelog/12835.improvement.md | 2 +- docs/docs/tracker-stores.mdx | 2 ++ rasa/core/tracker_store.py | 2 ++ tests/core/test_lock_store.py | 44 ++++++++++++++++++++++++++++++- tests/core/test_tracker_stores.py | 2 ++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/changelog/12835.improvement.md b/changelog/12835.improvement.md index 4869a372b594..0fea8ac19d52 100644 --- a/changelog/12835.improvement.md +++ b/changelog/12835.improvement.md @@ -1 +1 @@ -Added `username` to the connection parameters for `RedisLockStore` \ No newline at end of file +Added `username` to the connection parameters for `RedisLockStore` and `RedisTrackerStore` \ No newline at end of file diff --git a/docs/docs/tracker-stores.mdx b/docs/docs/tracker-stores.mdx index f3ac71f4a2d1..f0485583c451 100644 --- a/docs/docs/tracker-stores.mdx +++ b/docs/docs/tracker-stores.mdx @@ -219,6 +219,8 @@ To set up Rasa with Redis the following steps are required: * `key_prefix` (default: `None`): The prefix to prepend to tracker store keys. Must be alphanumeric +* `username` (default: `None`): Username used for authentication + * `password` (default: `None`): Password used for authentication (`None` equals no authentication) diff --git a/rasa/core/tracker_store.py b/rasa/core/tracker_store.py index 2d38d22c26f3..adcabfc1388e 100644 --- a/rasa/core/tracker_store.py +++ b/rasa/core/tracker_store.py @@ -453,6 +453,7 @@ def __init__( host: Text = "localhost", port: int = 6379, db: int = 0, + username: Optional[Text] = None, password: Optional[Text] = None, event_broker: Optional[EventBroker] = None, record_exp: Optional[float] = None, @@ -470,6 +471,7 @@ def __init__( host=host, port=port, db=db, + username=username, password=password, ssl=use_ssl, ssl_keyfile=ssl_keyfile, diff --git a/tests/core/test_lock_store.py b/tests/core/test_lock_store.py index bba472696197..e182e3beb5ef 100644 --- a/tests/core/test_lock_store.py +++ b/tests/core/test_lock_store.py @@ -25,7 +25,10 @@ DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX, ) from rasa.shared.exceptions import ConnectionException -from rasa.utils.endpoints import EndpointConfig +from rasa.utils.endpoints import EndpointConfig, read_endpoint_config + +from typing import Text +from rasa.shared.core.domain import Domain class FakeRedisLockStore(RedisLockStore): @@ -384,3 +387,42 @@ async def test_redis_lock_store_with_valid_prefix(monkeypatch: MonkeyPatch): with pytest.raises(LockError): async with lock_store.lock("some sender"): pass + + +def test_tracker_store_endpoint_config_loading(endpoints_path: Text): + cfg = read_endpoint_config(endpoints_path, "tracker_store") + + assert cfg == EndpointConfig.from_dict( + { + "type": "redis", + "url": "localhost", + "port": 6379, + "db": 0, + "username": "username", + "password": "password", + "timeout": 30000, + "use_ssl": True, + "ssl_keyfile": "keyfile.key", + "ssl_certfile": "certfile.crt", + "ssl_ca_certs": "my-bundle.ca-bundle", + } + ) + + +def test_create_lock_store_from_endpoint_config(domain: Domain, endpoints_path: Text): + store = read_endpoint_config(endpoints_path, "tracker_store") + tracker_store = RedisLockStore( + domain=domain, + host="localhost", + port=6379, + db=0, + username="username", + password="password", + record_exp=3000, + use_ssl=True, + ssl_keyfile="keyfile.key", + ssl_certfile="certfile.crt", + ssl_ca_certs="my-bundle.ca-bundle", + ) + + assert isinstance(tracker_store, type(LockStore.create(store, domain))) diff --git a/tests/core/test_tracker_stores.py b/tests/core/test_tracker_stores.py index e0175dad8881..811061ccedf4 100644 --- a/tests/core/test_tracker_stores.py +++ b/tests/core/test_tracker_stores.py @@ -143,6 +143,7 @@ def test_tracker_store_endpoint_config_loading(endpoints_path: Text): "url": "localhost", "port": 6379, "db": 0, + "username": "username", "password": "password", "timeout": 30000, "use_ssl": True, @@ -162,6 +163,7 @@ def test_create_tracker_store_from_endpoint_config( host="localhost", port=6379, db=0, + username="username", password="password", record_exp=3000, use_ssl=True,