mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
handle failed db connections
This commit is contained in:
parent
0a401ee468
commit
6e5d2b1ac7
1 changed files with 0 additions and 33 deletions
|
@ -13,9 +13,6 @@ sys.path.insert(
|
||||||
) # Adds the parent directory to the system path
|
) # Adds the parent directory to the system path
|
||||||
import pytest, litellm
|
import pytest, litellm
|
||||||
import httpx
|
import httpx
|
||||||
from litellm.proxy.auth.auth_checks import (
|
|
||||||
_handle_failed_db_connection_for_get_key_object,
|
|
||||||
)
|
|
||||||
from litellm.proxy._types import UserAPIKeyAuth
|
from litellm.proxy._types import UserAPIKeyAuth
|
||||||
from litellm.proxy.auth.auth_checks import get_end_user_object
|
from litellm.proxy.auth.auth_checks import get_end_user_object
|
||||||
from litellm.caching.caching import DualCache
|
from litellm.caching.caching import DualCache
|
||||||
|
@ -78,36 +75,6 @@ async def test_get_end_user_object(customer_spend, customer_budget):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_handle_failed_db_connection():
|
|
||||||
"""
|
|
||||||
Test cases:
|
|
||||||
1. When allow_requests_on_db_unavailable=True -> return UserAPIKeyAuth
|
|
||||||
2. When allow_requests_on_db_unavailable=False -> raise original error
|
|
||||||
"""
|
|
||||||
from litellm.proxy.proxy_server import general_settings, litellm_proxy_admin_name
|
|
||||||
|
|
||||||
# Test case 1: allow_requests_on_db_unavailable=True
|
|
||||||
general_settings["allow_requests_on_db_unavailable"] = True
|
|
||||||
mock_error = httpx.ConnectError("Failed to connect to DB")
|
|
||||||
|
|
||||||
result = await _handle_failed_db_connection_for_get_key_object(e=mock_error)
|
|
||||||
|
|
||||||
assert isinstance(result, UserAPIKeyAuth)
|
|
||||||
assert result.key_name == "failed-to-connect-to-db"
|
|
||||||
assert result.token == "failed-to-connect-to-db"
|
|
||||||
assert result.user_id == litellm_proxy_admin_name
|
|
||||||
|
|
||||||
# Test case 2: allow_requests_on_db_unavailable=False
|
|
||||||
general_settings["allow_requests_on_db_unavailable"] = False
|
|
||||||
|
|
||||||
with pytest.raises(httpx.ConnectError) as exc_info:
|
|
||||||
await _handle_failed_db_connection_for_get_key_object(e=mock_error)
|
|
||||||
print("_handle_failed_db_connection_for_get_key_object got exception", exc_info)
|
|
||||||
|
|
||||||
assert str(exc_info.value) == "Failed to connect to DB"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"model, expect_to_work",
|
"model, expect_to_work",
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue