From e0917eebaae6faf1feecdb109dba27d759644bcb Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 23 Apr 2024 19:10:06 -0700 Subject: [PATCH] fix test alerting --- litellm/tests/test_alerting.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/litellm/tests/test_alerting.py b/litellm/tests/test_alerting.py index 6cb0e29edc..311b803110 100644 --- a/litellm/tests/test_alerting.py +++ b/litellm/tests/test_alerting.py @@ -4,7 +4,7 @@ import sys import os import io, asyncio -from datetime import datetime +from datetime import datetime, timedelta # import logging # logging.basicConfig(level=logging.DEBUG) @@ -13,6 +13,10 @@ from litellm.proxy.utils import ProxyLogging from litellm.caching import DualCache import litellm import pytest +import asyncio +from unittest.mock import patch, MagicMock +from litellm.caching import DualCache +from litellm.integrations.slack_alerting import SlackAlerting @pytest.mark.asyncio @@ -43,7 +47,7 @@ async def test_get_api_base(): end_time = datetime.now() time_difference_float, model, api_base, messages = ( - _pl._response_taking_too_long_callback( + _pl.slack_alerting_instance._response_taking_too_long_callback( kwargs={ "model": model, "messages": messages, @@ -65,3 +69,27 @@ async def test_get_api_base(): message=slow_message + request_info, level="Low", ) + print("passed test_get_api_base") + + +# Create a mock environment for testing +@pytest.fixture +def mock_env(monkeypatch): + monkeypatch.setenv("SLACK_WEBHOOK_URL", "https://example.com/webhook") + monkeypatch.setenv("LANGFUSE_HOST", "https://cloud.langfuse.com") + monkeypatch.setenv("LANGFUSE_PROJECT_ID", "test-project-id") + + +# Test the __init__ method +def test_init(): + slack_alerting = SlackAlerting( + alerting_threshold=32, alerting=["slack"], alert_types=["llm_exceptions"] + ) + assert slack_alerting.alerting_threshold == 32 + assert slack_alerting.alerting == ["slack"] + assert slack_alerting.alert_types == ["llm_exceptions"] + + slack_no_alerting = SlackAlerting() + assert slack_no_alerting.alerting == [] + + print("passed testing slack alerting init")