Files
owi-litellm-tool/tests/integration_test.py
T

64 lines
2.4 KiB
Python

import unittest
import os
import sys
from litellm_dashboard import Tools
# Note: Integration key is NOT stored in repo. It is read from /tmp at runtime.
INTEGRATION_KEY_PATH = "/tmp/litellm-integration-testing-key.txt"
LIVE_URL = "http://mon-serv1.captcouch.xyz:4001"
class TestLiteLLMTool(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tools = Tools()
cls.tools.valves.litellm_url = LIVE_URL
if os.path.exists(INTEGRATION_KEY_PATH):
with open(INTEGRATION_KEY_PATH, 'r') as f:
cls.tools.valves.litellm_master_key = f.read().strip()
else:
print("Warning: Integration key not found. Some tests will fail.")
def test_litellm_status_integration(self):
"""Test lean status snapshot against live instance."""
output = self.tools.litellm_status()
print("\n--- Status Output ---")
print(output)
self.assertIn("LiteLLM Status Snapshot", output)
self.assertIn("Proxy: ✅", output)
if self.tools.valves.litellm_master_key:
self.assertIn("Lifetime Spend:", output)
def test_litellm_health_integration(self):
"""Test health check against live instance."""
output = self.tools.litellm_health()
self.assertIn("LiteLLM Health Check", output)
self.assertIn("Healthy:", output)
def test_litellm_cost_visualization_integration(self):
"""Test cost report and sparkline logic."""
output = self.tools.litellm_cost(start_date="3 days ago", end_date="today")
print("\n--- Cost Output ---")
print(output)
self.assertIn("Total Spend:", output)
self.assertIn("[", output) # Part of sparkline check
self.assertIn("]", output)
def test_litellm_history_audit_integration(self):
"""Test request history and Dynamic Audit Engine."""
output = self.tools.litellm_history(limit=5)
print("\n--- History Output ---")
print(output)
self.assertIn("LiteLLM History", output)
# Check if audit engine is firing (either calc ok or mismatch)
self.assertTrue("calc:" in output or "History" in output)
def test_date_resolution(self):
"""Unit test for date resolver."""
d1 = self.tools._resolve_date("today")
d2 = self.tools._resolve_date("yesterday")
self.assertNotEqual(d1, d2)
self.assertEqual(len(d1), 10) # YYYY-MM-DD
if __name__ == "__main__":
unittest.main()