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
This commit is contained in:
Alexsander Hamir 2025-11-22 10:44:23 -08:00 • committed by GitHub
parent 2a92e97d63
commit ca2a27c377
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -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(

View file

@ -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: