Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

quality: Add cache tests

Clémence Lesné93342ff47e1d
diff --git a/tests/cache.py b/tests/cache.py
new file mode 100644
index 0000000..3d93438
--- /dev/null
+++ b/tests/cache.py
@@ -0,0 +1,38 @@
+from helpers.config import CONFIG
+from helpers.config_models.cache import ModeEnum as CacheModeEnum
+import pytest
+
+
+_cache = CONFIG.cache.instance()
+
+
+ "cache_mode",
+ [
+ pytest.param(
+ CacheModeEnum.MEMORY,
+ id="memory",
+ ),
+ pytest.param(
+ CacheModeEnum.REDIS,
+ id="redis",
+ ),
+ ],
+)
+async def test_acid(random_text: str, cache_mode: CacheModeEnum) -> None:
+ # Set cache mode
+ CONFIG.cache.mode = cache_mode
+
+ # Init values
+ test_key = random_text
+ test_value = "lorem ipsum"
+
+ # Check not exists
+ assert not await _cache.aget(test_key)
+
+ # Insert test call
+ await _cache.aset(test_key, test_value)
+
+ # Check point read
+ assert await _cache.aget(test_key) == test_value.encode()
diff --git a/tests/conftest.py b/tests/conftest.py
index 0a1f92e..2980513 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -23,6 +23,12 @@ import xml.etree.ElementTree as ET
_logger = build_logger(__name__)
+def random_text() -> str:
+ text = "".join(random.choice(string.printable) for _ in range(100))
+ return text
+
+
@pytest.fixture
def call_mock() -> CallModel:
phone_number = "+336" + "".join(random.choice("0123456789") for _ in range(8))