|
2 | 2 |
|
3 | 3 |
|
4 | 4 | def test_get_cached_json_returns_none_without_redis_url(monkeypatch): |
| 5 | + counters: list[tuple[str, int | float, dict[str, str]]] = [] |
| 6 | + |
5 | 7 | monkeypatch.setattr(analytics_cache_service.settings, "analytics_cache_enabled", True) |
6 | 8 | monkeypatch.setattr(analytics_cache_service.settings, "redis_url", "") |
| 9 | + monkeypatch.setattr( |
| 10 | + analytics_cache_service, |
| 11 | + "record_counter", |
| 12 | + lambda name, value, attributes=None: counters.append((name, value, attributes or {})), |
| 13 | + ) |
7 | 14 | analytics_cache_service._redis_client = None |
8 | 15 | analytics_cache_service._redis_disabled_until = None |
9 | 16 |
|
10 | 17 | assert analytics_cache_service.get_cached_json("overview", {"team_id": None}) is None |
| 18 | + assert counters == [] |
11 | 19 |
|
12 | 20 |
|
13 | 21 | def test_set_cached_json_noops_without_redis_url(monkeypatch): |
| 22 | + counters: list[tuple[str, int | float, dict[str, str]]] = [] |
| 23 | + |
14 | 24 | monkeypatch.setattr(analytics_cache_service.settings, "analytics_cache_enabled", True) |
15 | 25 | monkeypatch.setattr(analytics_cache_service.settings, "redis_url", "") |
| 26 | + monkeypatch.setattr( |
| 27 | + analytics_cache_service, |
| 28 | + "record_counter", |
| 29 | + lambda name, value, attributes=None: counters.append((name, value, attributes or {})), |
| 30 | + ) |
16 | 31 | analytics_cache_service._redis_client = None |
17 | 32 | analytics_cache_service._redis_disabled_until = None |
18 | 33 |
|
19 | 34 | analytics_cache_service.set_cached_json("overview", {"team_id": None}, {"total_sessions": 1}) |
| 35 | + assert counters == [] |
20 | 36 |
|
21 | 37 |
|
22 | 38 | def test_get_cached_json_backs_off_after_redis_error(monkeypatch): |
|
0 commit comments