This commit is contained in:
Mateo Wang 2026-08-27 16:38:08 -05:00 committed by GitHub
commit 7f3ee3d41b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 13 deletions

View file

@ -0,0 +1,9 @@
import pytest
@pytest.fixture(autouse=True)
def isolate_from_real_cli_token(monkeypatch):
"""Never let tests read the developer's real ~/.litellm/token.json from `lite login`."""
monkeypatch.setattr(
"litellm.litellm_core_utils.cli_token_utils.load_cli_token", lambda: None
)

View file

@ -69,18 +69,40 @@ def test_client_without_api_key_propagates_none_to_resource_clients(base_url):
assert client.http._api_key is None
def test_client_initialization():
"""Test that the client is initialized correctly."""
def test_client_falls_back_to_stored_cli_token(base_url, monkeypatch):
"""Test that the client uses the `lite login` token issued for this server"""
monkeypatch.setattr(
"litellm.litellm_core_utils.cli_token_utils.load_cli_token",
lambda: {"key": "sk-cli-token", "base_url": base_url},
)
client = Client(base_url=base_url)
assert client._api_key == "sk-cli-token"
assert client.http._api_key == "sk-cli-token"
def test_client_ignores_cli_token_issued_for_other_server(base_url, monkeypatch):
"""Test that the client never sends a stored CLI token to a different server"""
monkeypatch.setattr(
"litellm.litellm_core_utils.cli_token_utils.load_cli_token",
lambda: {"key": "sk-cli-token", "base_url": "https://other-proxy.example"},
)
client = Client(base_url=base_url)
assert client._api_key is None
assert client.http._api_key is None
def test_client_custom_timeout():
"""Test that the client passes a custom timeout to the http client."""
client = Client(
base_url="http://localhost:4000",
api_key="test-key",
timeout=60,
)
# Check that http client is initialized correctly
assert isinstance(client.http, HTTPClient)
assert client.http._base_url == "http://localhost:4000"
assert client.http._api_key == "test-key"
assert client.http._timeout == 60
@ -92,10 +114,3 @@ def test_client_default_timeout():
)
assert client.http._timeout == 30
def test_client_without_api_key():
"""Test that the client works without an API key."""
client = Client(base_url="http://localhost:4000")
assert client.http._api_key is None