fix unit tc failure due to updated logic

This commit is contained in:
Sumit Jaiswal 2025-05-31 08:05:04 +05:30
parent 9c42598aee
commit ae85dd6182
No known key found for this signature in database
GPG key ID: A4604B39D64D6AEC

View file

@ -650,16 +650,22 @@ async def test_health_status_success(vllm_inference_adapter):
This test verifies that the health method returns a HealthResponse with status OK, only This test verifies that the health method returns a HealthResponse with status OK, only
when the connection to the vLLM server is successful. when the connection to the vLLM server is successful.
""" """
# Mock the requests.get method to return a successful response # Mock the client.models.list method to return successfully
with patch('requests.get') as mock_get: # Set vllm_inference_adapter.client to None to ensure _create_client is called
mock_response = MagicMock() vllm_inference_adapter.client = None
mock_response.status_code = 200 with patch.object(vllm_inference_adapter, '_create_client') as mock_create_client:
mock_get.return_value = mock_response # Create mock client and models
mock_client = MagicMock()
mock_models = MagicMock()
mock_client.models = mock_models
mock_create_client.return_value = mock_client
# Call the health method # Call the health method
health_response = await vllm_inference_adapter.health() health_response = await vllm_inference_adapter.health()
# Verify the response # Verify the response
assert health_response["status"] == HealthStatus.OK assert health_response["status"] == HealthStatus.OK
mock_get.assert_called_once()
# Verify that models.list was called
mock_models.list.assert_called_once()
@pytest.mark.asyncio @pytest.mark.asyncio
@ -670,12 +676,19 @@ async def test_health_status_failure(vllm_inference_adapter):
This test verifies that the health method returns a HealthResponse with status ERROR This test verifies that the health method returns a HealthResponse with status ERROR
and an appropriate error message when the connection to the vLLM server fails. and an appropriate error message when the connection to the vLLM server fails.
""" """
# Mock the requests.get method to raise an exception vllm_inference_adapter.client = None
with patch('requests.get') as mock_get: # Mock the client.models.list method to raise an exception
mock_get.side_effect = Exception("Connection failed") with patch.object(vllm_inference_adapter, '_create_client') as mock_create_client:
# Create mock client and models
mock_client = MagicMock()
mock_models = MagicMock()
mock_models.list.side_effect = Exception("Connection failed")
mock_client.models = mock_models
mock_create_client.return_value = mock_client
# Call the health method
health_response = await vllm_inference_adapter.health() health_response = await vllm_inference_adapter.health()
# Verify the response # Verify the response
assert health_response["status"] == HealthStatus.ERROR assert health_response["status"] == HealthStatus.ERROR
assert "Health check failed: Connection failed" in health_response["message"] assert "Health check failed: Connection failed" in health_response["message"]
# Verify that requests.get was called
mock_get.assert_called_once() mock_models.list.assert_called_once()