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_encode_decode_helpers_roundtrip_in_cache_context

Ishaan Jafferb855ad5541fd
diff --git a/tests/test_litellm/containers/test_container_api.py b/tests/test_litellm/containers/test_container_api.py
index d4c42b0b3d6..c7bb68e79cb 100644
--- a/tests/test_litellm/containers/test_container_api.py
+++ b/tests/test_litellm/containers/test_container_api.py
@@ -134,80 +134,6 @@ class TestContainerAPI:
assert response.id == "cntr_async_123"
assert response.name == "Async Test Container"
- def test_list_containers_basic(self):
- """Test basic container listing functionality."""
- mock_response = ContainerListResponse(
- object="list",
- data=[
- ContainerObject(
- id="cntr_1",
- object="container",
- created_at=1747857508,
- status="running",
- expires_after={"anchor": "last_active_at", "minutes": 20},
- last_active_at=1747857508,
- name="Container 1"
- ),
- ContainerObject(
- id="cntr_2",
- object="container",
- created_at=1747857600,
- status="running",
- expires_after={"anchor": "last_active_at", "minutes": 15},
- last_active_at=1747857600,
- name="Container 2"
- )
- ],
- first_id="cntr_1",
- last_id="cntr_2",
- has_more=False
- )
-
- with patch('litellm.containers.main.base_llm_http_handler') as mock_handler:
- mock_handler.container_list_handler.return_value = mock_response
-
- response = list_containers(
- custom_llm_provider="openai"
- )
-
- assert isinstance(response, ContainerListResponse)
- assert len(response.data) == 2
- assert response.data[0].id == "cntr_1"
- assert response.data[1].id == "cntr_2"
- assert response.has_more == False
-
- def test_list_containers_with_params(self):
- """Test container listing with parameters."""
- mock_response = ContainerListResponse(
- object="list",
- data=[
- ContainerObject(
- id="cntr_limited",
- object="container",
- created_at=1747857508,
- status="running",
- expires_after={"anchor": "last_active_at", "minutes": 20},
- last_active_at=1747857508,
- name="Limited Container"
- )
- ],
- first_id="cntr_limited",
- last_id="cntr_limited",
- has_more=True
- )
-
- with patch('litellm.containers.main.base_llm_http_handler') as mock_handler:
- mock_handler.container_list_handler.return_value = mock_response
-
- response = list_containers(
- limit=1,
- order="desc",
- after="cntr_prev",
- custom_llm_provider="openai"
- )
-
- assert len(response.data) == 1
- assert response.has_more == True
@pytest.mark.asyncio
async def test_alist_containers_basic(self):
diff --git a/tests/test_litellm/integrations/gitlab/test_gitlab_prompt_manager.py b/tests/test_litellm/integrations/gitlab/test_gitlab_prompt_manager.py
index 8475252cfc2..637b2a5ae51 100644
--- a/tests/test_litellm/integrations/gitlab/test_gitlab_prompt_manager.py
+++ b/tests/test_litellm/integrations/gitlab/test_gitlab_prompt_manager.py
@@ -1,18 +1,19 @@
import os
import sys
from unittest.mock import MagicMock, patch
+
import pytest
sys.path.insert(0, os.path.abspath("../../..")) # Adds the parent directory to the system path
from litellm.integrations.gitlab.gitlab_client import GitLabClient
from litellm.integrations.gitlab.gitlab_prompt_manager import (
+ GitLabPromptCache,
GitLabPromptManager,
GitLabPromptTemplate,
GitLabTemplateManager,
- GitLabPromptCache,
- encode_prompt_id,
decode_prompt_id,
+ encode_prompt_id,
)
# -----------------------
@@ -817,8 +818,10 @@ def test_cache_get_by_file_returns_exact_entry(mock_pm_cls, fake_managers):
assert beta and beta["id"] == "nested/beta"
+@patch("litellm.integrations.gitlab.gitlab_prompt_manager.GitLabClient")
@patch("litellm.integrations.gitlab.gitlab_prompt_manager.GitLabPromptManager")
-def test_encode_decode_helpers_roundtrip_in_cache_context(mock_pm_cls, fake_managers):
+def test_encode_decode_helpers_roundtrip_in_cache_context(mock_pm_cls, mock_client_cls, fake_managers):
+ """Test that encode/decode helpers work correctly in the cache context."""
tm, wrapper = fake_managers
tm._discoverable_ids = ["dir1/dir2/item"]
mock_pm_cls.return_value = wrapper
@@ -826,10 +829,13 @@ def test_encode_decode_helpers_roundtrip_in_cache_context(mock_pm_cls, fake_mana
cache = GitLabPromptCache({"project": "g/s/r", "access_token": "tkn"})
cache.load_all()
+ # Verify mock was used
+ mock_pm_cls.assert_called_once()
+
encoded = encode_prompt_id("dir1/dir2/item")
assert encoded in cache.list_ids()
- # decode → encode → lookup should still work
+ # decode -> encode -> lookup should still work
decoded = decode_prompt_id(encoded)
assert decoded == "dir1/dir2/item"
diff --git a/tests/test_litellm/test_responses_id_security.py b/tests/test_litellm/test_responses_id_security.py
index e72a09ee0d3..67b0afcadd9 100644
--- a/tests/test_litellm/test_responses_id_security.py
+++ b/tests/test_litellm/test_responses_id_security.py
@@ -139,7 +139,7 @@ class TestEncryptResponseId:
"litellm.proxy.hooks.responses_id_security.encrypt_value_helper"
) as mock_encrypt:
mock_encrypt.return_value = "encrypted_value_456"
-
+
with patch.object(
responses_id_security, "_get_signing_key", return_value="test-key"
):
@@ -147,7 +147,9 @@ class TestEncryptResponseId:
mock_response, mock_user_api_key_dict
)
+ assert result.id == "resp_encrypted_value_456"
assert result.id.startswith("resp_")
+ mock_encrypt.assert_called_once()
class TestCheckUserAccessToResponseId: