@@ -573,25 +573,32 @@ async def test_generate_content_async_other_client_error(
573573
574574@pytest .mark .asyncio
575575async def test_connect (gemini_llm , llm_request ):
576- # Create a mock connection
577- mock_connection = mock .MagicMock ( spec = GeminiLlmConnection )
576+ """Test that connect yields a GeminiLlmConnection wrapping the live session."""
577+ mock_live_session = mock .AsyncMock ( )
578578
579- # Create a mock context manager
580- class MockContextManager :
579+ # Patch the live API client boundary so the real connect() body runs.
580+ with mock . patch . object ( gemini_llm , "_live_api_client" ) as mock_live_client :
581581
582- async def __aenter__ (self ):
583- return mock_connection
582+ class MockLiveConnect :
584583
585- async def __aexit__ (self , * args ):
586- pass
584+ async def __aenter__ (self ):
585+ return mock_live_session
586+
587+ async def __aexit__ (self , * args ):
588+ pass
589+
590+ mock_live_client .aio .live .connect .return_value = MockLiveConnect ()
587591
588- # Mock the connect method at the class level
589- with mock .patch (
590- "google.adk.models.google_llm.Gemini.connect" ,
591- return_value = MockContextManager (),
592- ):
593592 async with gemini_llm .connect (llm_request ) as connection :
594- assert connection is mock_connection
593+ mock_live_client .aio .live .connect .assert_called_once ()
594+ call_args = mock_live_client .aio .live .connect .call_args
595+ assert call_args .kwargs ["model" ] == llm_request .model
596+ assert call_args .kwargs ["config" ] is llm_request .live_connect_config
597+
598+ assert isinstance (connection , GeminiLlmConnection )
599+ assert connection ._gemini_session is mock_live_session
600+ assert connection ._api_backend == gemini_llm ._api_backend
601+ assert connection ._model_version == llm_request .model
595602
596603
597604@pytest .mark .asyncio
0 commit comments