From b855ad5541fdd5dcc20a7694039494bb914cbcf3 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 7 Jan 2026 18:23:17 +0530 Subject: [PATCH] test_encode_decode_helpers_roundtrip_in_cache_context --- .../containers/test_container_api.py | 74 ------------------- .../gitlab/test_gitlab_prompt_manager.py | 14 +++- .../test_responses_id_security.py | 4 +- 3 files changed, 13 insertions(+), 79 deletions(-) diff --git a/tests/test_litellm/containers/test_container_api.py b/tests/test_litellm/containers/test_container_api.py index d4c42b0b3d..c7bb68e79c 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 8475252cfc..637b2a5ae5 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 e72a09ee0d..67b0afcadd 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: