sirus / backend /SQL_Agent /tests /test_tenant_billing_ledger.py
ranilmukesh's picture
Deploy SiRUS SQL Agent backend
a8c9ee8
from unittest.mock import MagicMock
from backend.SQL_Agent import agent
def test_record_tenant_billing_updates_redis_hash(monkeypatch):
mock_redis = MagicMock()
monkeypatch.setattr(agent, "_get_billing_redis", lambda: mock_redis)
agent.record_tenant_billing("tenant_ledger", input_tokens=1200, output_tokens=800)
mock_redis.hincrby.assert_any_call("tenant_billing:tenant_ledger", "input_tokens", 1200)
mock_redis.hincrby.assert_any_call("tenant_billing:tenant_ledger", "output_tokens", 800)
mock_redis.hincrby.assert_any_call("tenant_billing:tenant_ledger", "total_tokens", 2000)
assert mock_redis.hincrbyfloat.called