refactor(redis): strengthen shared cache invalidation

This commit is contained in:
3252a8
2026-05-21 06:26:48 +03:00
parent 3405d12696
commit 044cb4de7e
10 changed files with 237 additions and 61 deletions
+38
View File
@@ -0,0 +1,38 @@
import unittest
from types import SimpleNamespace
from unittest.mock import patch
import bot.app.web.subscription_webapp # noqa: F401
from bot.app.web.webapp import common as common_module
class WebappRedisCacheInvalidationTests(unittest.IsolatedAsyncioTestCase):
async def test_invalidate_webapp_user_caches_deletes_me_and_devices_keys(self):
settings = SimpleNamespace(REDIS_URL="redis://redis:6379/0", REDIS_KEY_PREFIX="shop")
deleted = []
async def fake_delete(_settings, *keys):
deleted.extend(keys)
with patch.object(common_module, "cache_delete", fake_delete):
await common_module._invalidate_webapp_user_caches(
settings,
42,
"42",
99,
include_devices=True,
)
self.assertEqual(
deleted,
[
"shop:cache:webapp:me:42",
"shop:cache:webapp:devices:42",
"shop:cache:webapp:me:99",
"shop:cache:webapp:devices:99",
],
)
if __name__ == "__main__":
unittest.main()