litellm/tests/unit/proxy/common_utils/test_realtime_cache.py
Mateo Wang 58258409c9
refactor(proxy): expose public names for private proxy helpers (#45170)
* refactor(proxy): expose public names for private proxy helpers

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): keep original class names behind public aliases

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): preserve internal callback filtering

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): keep _PROXY_ class names for managed files hooks

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): keep old private names in package exports

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): preserve recursive auth helper name

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(proxy): align MCP limiter tests with server enforcement

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(proxy): match main's MCP limiter tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): keep old private names bound in importing modules

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): preserve compatibility imports through strict lint

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(proxy): use exact pyright suppression in password helper test

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* style(proxy): add reasons to compatibility import noqa comments

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(proxy): update IN-list baseline for renamed helpers

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-07 18:59:27 -07:00

63 lines
2.4 KiB
Python

from typing import Any, cast
import pytest
from litellm.proxy.common_utils.realtime_utils import realtime_request_body
from litellm.proxy.proxy_server import _realtime_query_params_template
@pytest.fixture(autouse=True)
def clear_realtime_caches():
realtime_request_body.cache_clear()
_realtime_query_params_template.cache_clear()
yield
realtime_request_body.cache_clear()
_realtime_query_params_template.cache_clear()
def test_realtime_request_body_returns_immutable_bytes():
cached_body = realtime_request_body("gpt-4o")
with pytest.raises(TypeError):
cast(Any, cached_body)[0] = ord("x")
def test_realtime_query_params_template_returns_immutable_tuples():
cached_tuple = _realtime_query_params_template("gpt-4o", "intent-a")
with pytest.raises(TypeError):
cast(Any, cached_tuple)[0] = ("model", "mutated")
def test_realtime_request_body_caches_each_model_separately():
gpt4o_body_first = realtime_request_body("gpt-4o")
gpt4o_body_second = realtime_request_body("gpt-4o")
gpt4o_mini_body = realtime_request_body("gpt-4o-mini")
assert gpt4o_body_first is gpt4o_body_second
assert gpt4o_body_first == b'{"model": "gpt-4o"}'
assert gpt4o_mini_body == b'{"model": "gpt-4o-mini"}'
assert gpt4o_body_first is not gpt4o_mini_body
def test_realtime_query_params_template_caches_each_pair_separately():
params_with_intent_first = _realtime_query_params_template("gpt-4o", "intent-a")
params_with_intent_second = _realtime_query_params_template("gpt-4o", "intent-a")
params_without_intent = _realtime_query_params_template("gpt-4o", None)
params_transcription_without_model = _realtime_query_params_template(None, "transcription")
assert params_with_intent_first is params_with_intent_second
assert params_with_intent_first == (("model", "gpt-4o"), ("intent", "intent-a"))
assert params_without_intent == (("model", "gpt-4o"),)
assert params_transcription_without_model == (("intent", "transcription"),)
assert params_with_intent_first is not params_without_intent
def test_realtime_query_params_dict_copies_do_not_leak_state():
params_dict_one = dict(_realtime_query_params_template("gpt-4o", "intent-a"))
params_dict_one["new"] = "value"
params_dict_two = dict(_realtime_query_params_template("gpt-4o", "intent-a"))
assert "new" not in params_dict_two
assert params_dict_two == {"model": "gpt-4o", "intent": "intent-a"}