Skip to content

Commit

Permalink
add tests and username in RedisTrackerStore
Browse files Browse the repository at this point in the history
  • Loading branch information
vcidst committed Sep 20, 2023
1 parent 0bfc8f9 commit e780ff3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion changelog/12835.improvement.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added `username` to the connection parameters for `RedisLockStore`
Added `username` to the connection parameters for `RedisLockStore` and `RedisTrackerStore`
2 changes: 2 additions & 0 deletions docs/docs/tracker-stores.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions rasa/core/tracker_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -470,6 +471,7 @@ def __init__(
host=host,
port=port,
db=db,
username=username,
password=password,
ssl=use_ssl,
ssl_keyfile=ssl_keyfile,
Expand Down
44 changes: 43 additions & 1 deletion tests/core/test_lock_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)))
2 changes: 2 additions & 0 deletions tests/core/test_tracker_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit e780ff3

Please sign in to comment.