Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test_retrieve_container_basic

Ishaan Jaffer9f99e8231cda
diff --git a/tests/test_litellm/containers/test_container_api.py b/tests/test_litellm/containers/test_container_api.py
index 3937c791660..f489447ca99 100644
--- a/tests/test_litellm/containers/test_container_api.py
+++ b/tests/test_litellm/containers/test_container_api.py
@@ -166,30 +166,55 @@ class TestContainerAPI:
assert isinstance(response, ContainerListResponse)
assert len(response.data) == 1
- def test_retrieve_container_basic(self):
- """Test basic container retrieval functionality."""
- container_id = "cntr_retrieve_test"
+ @pytest.mark.parametrize(
+ "container_id,container_name,status,provider",
+ [
+ ("cntr_retrieve_test", "Retrieved Container", "running", "openai"),
+ ("cntr_different_id", "Another Container", "stopped", "openai"),
+ ],
+ )
+ def test_retrieve_container_basic(self, container_id, container_name, status, provider):
+ """Test basic container retrieval functionality.
+
+ This test verifies that:
+ 1. retrieve_container correctly calls the handler with the container_id
+ 2. The response is properly deserialized into a ContainerObject
+ 3. All fields are correctly mapped from the handler response
+ 4. The function works with different container states and IDs
+ """
+ # Arrange: Create mock response with test parameters
mock_response = ContainerObject(
id=container_id,
object="container",
created_at=1747857508,
- status="running",
+ status=status,
expires_after={"anchor": "last_active_at", "minutes": 20},
last_active_at=1747857508,
- name="Retrieved Container"
+ name=container_name
)
- with patch('litellm.containers.main.base_llm_http_handler.container_retrieve_handler') as mock_handler:
- mock_handler.return_value = mock_response
+ with patch('litellm.containers.main.base_llm_http_handler') as mock_handler:
+ mock_handler.container_retrieve_handler.return_value = mock_response
+ # Act: Call retrieve_container
response = retrieve_container(
container_id=container_id,
- custom_llm_provider="openai"
+ custom_llm_provider=provider
)
+ # Assert: Verify the handler was called correctly
+ mock_handler.container_retrieve_handler.assert_called_once()
+ call_kwargs = mock_handler.container_retrieve_handler.call_args.kwargs
+ assert call_kwargs["container_id"] == container_id
+
+ # Assert: Verify response structure and content
assert isinstance(response, ContainerObject)
assert response.id == container_id
- assert response.name == "Retrieved Container"
+ assert response.name == container_name
+ assert response.status == status
+ assert response.object == "container"
+ assert response.expires_after.minutes == 20
+ assert response.expires_after.anchor == "last_active_at"
@pytest.mark.asyncio
async def test_aretrieve_container_basic(self):