From ca2a27c3778fcf554cb88651c2af28765c2c7af5 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Sat, 22 Nov 2025 10:44:23 -0800 Subject: [PATCH] fix: add missing mock attributes in websocket and realtime tests (#16974) - Add scope and url attributes to WebSocket mock in test_user_api_key_auth_websocket - Add shared_realtime_ssl_context initialization in realtime handler test --- tests/proxy_unit_tests/test_user_api_key_auth.py | 4 ++++ .../llms/openai/realtime/test_openai_realtime_handler.py | 1 + 2 files changed, 5 insertions(+) diff --git a/tests/proxy_unit_tests/test_user_api_key_auth.py b/tests/proxy_unit_tests/test_user_api_key_auth.py index 2d7de01ec0a..1e3ec1e3019 100644 --- a/tests/proxy_unit_tests/test_user_api_key_auth.py +++ b/tests/proxy_unit_tests/test_user_api_key_auth.py @@ -827,6 +827,10 @@ async def test_user_api_key_auth_websocket(): mock_websocket = MagicMock(spec=WebSocket) mock_websocket.query_params = {"model": "some_model"} mock_websocket.headers = {"authorization": "Bearer some_api_key"} + # Mock the scope attribute that user_api_key_auth_websocket accesses + mock_websocket.scope = {"headers": [(b"authorization", b"Bearer some_api_key")]} + # Mock the url attribute + mock_websocket.url = URL(url="/ws") # Mock the return value of `user_api_key_auth` when it's called within the `user_api_key_auth_websocket` function with patch( diff --git a/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py b/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py index bd973692c1e..3a446a2048e 100644 --- a/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py +++ b/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py @@ -168,6 +168,7 @@ async def test_async_realtime_url_contains_model(): async def __aexit__(self, exc_type, exc, tb): return None + shared_context = get_shared_realtime_ssl_context() with patch("websockets.connect", return_value=DummyAsyncContextManager(mock_backend_ws)) as mock_ws_connect, \ patch("litellm.llms.openai.realtime.handler.RealTimeStreaming") as mock_realtime_streaming: