From 1998fedd4a026c9a5482a4033eb0191230f67063 Mon Sep 17 00:00:00 2001 From: Kartik Chilkoti Date: Wed, 16 Sep 2026 17:06:14 +0530 Subject: [PATCH 1/2] test(budget): add spend threshold evaluation and budget reset arithmetic tests [skip ci] --- tests/test_budget_tracker_bounds.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_budget_tracker_bounds.py diff --git a/tests/test_budget_tracker_bounds.py b/tests/test_budget_tracker_bounds.py new file mode 100644 index 00000000000..27b3dcfdfcd --- /dev/null +++ b/tests/test_budget_tracker_bounds.py @@ -0,0 +1,30 @@ +\"\"\" +Unit tests for user and team budget tracking arithmetic and threshold evaluation in LiteLLM proxy. +\"\"\" +import pytest +from typing import Dict, Any + +def test_spend_threshold_exceeded(): + max_budget = 100.0 + current_spend = 95.50 + incoming_cost = 5.00 + + projected_spend = current_spend + incoming_cost + is_exceeded = projected_spend > max_budget + assert is_exceeded is True + assert round(projected_spend, 2) == 100.50 + +def test_spend_threshold_within_limit(): + max_budget = 50.0 + current_spend = 20.0 + incoming_cost = 12.50 + + projected_spend = current_spend + incoming_cost + is_exceeded = projected_spend > max_budget + assert is_exceeded is False + assert projected_spend == 32.50 + +def test_daily_budget_reset_calculation(): + budget_duration = "1d" + seconds_in_day = 86400 + assert seconds_in_day == 24 * 60 * 60 \ No newline at end of file From fe722203c65b5afbc0385109c52d60ababed4691 Mon Sep 17 00:00:00 2001 From: Kartik Chilkoti Date: Wed, 16 Sep 2026 20:18:27 +0530 Subject: [PATCH 2/2] test(cache): test litellm DualCache in-memory operations and cache misses --- tests/test_budget_tracker_bounds.py | 37 ++++++++--------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/tests/test_budget_tracker_bounds.py b/tests/test_budget_tracker_bounds.py index 27b3dcfdfcd..703c1f19c93 100644 --- a/tests/test_budget_tracker_bounds.py +++ b/tests/test_budget_tracker_bounds.py @@ -1,30 +1,13 @@ -\"\"\" -Unit tests for user and team budget tracking arithmetic and threshold evaluation in LiteLLM proxy. -\"\"\" import pytest -from typing import Dict, Any +from litellm.caching.caching import DualCache -def test_spend_threshold_exceeded(): - max_budget = 100.0 - current_spend = 95.50 - incoming_cost = 5.00 - - projected_spend = current_spend + incoming_cost - is_exceeded = projected_spend > max_budget - assert is_exceeded is True - assert round(projected_spend, 2) == 100.50 +def test_dual_cache_in_memory_set_get(): + cache = DualCache(in_memory_cache=True) + cache.set_cache(key="user_spend_123", value=45.50, ttl=300) + cached_val = cache.get_cache(key="user_spend_123") + assert cached_val == 45.50 -def test_spend_threshold_within_limit(): - max_budget = 50.0 - current_spend = 20.0 - incoming_cost = 12.50 - - projected_spend = current_spend + incoming_cost - is_exceeded = projected_spend > max_budget - assert is_exceeded is False - assert projected_spend == 32.50 - -def test_daily_budget_reset_calculation(): - budget_duration = "1d" - seconds_in_day = 86400 - assert seconds_in_day == 24 * 60 * 60 \ No newline at end of file +def test_dual_cache_miss(): + cache = DualCache(in_memory_cache=True) + val = cache.get_cache(key="non_existent_key_xyz") + assert val is None \ No newline at end of file