From 2df1be6055ac1a59af3d442ea008307198c56132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20M=C3=BCller?= Date: Fri, 27 Mar 2026 17:38:50 +0100 Subject: [PATCH] add unit test --- .../test_redact_messages.py | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/test_litellm/litellm_core_utils/test_redact_messages.py b/tests/test_litellm/litellm_core_utils/test_redact_messages.py index d7df7823aee..16fc6a99ecd 100644 --- a/tests/test_litellm/litellm_core_utils/test_redact_messages.py +++ b/tests/test_litellm/litellm_core_utils/test_redact_messages.py @@ -8,7 +8,10 @@ but litellm_params["litellm_metadata"] is None. import pytest import litellm -from litellm.litellm_core_utils.redact_messages import should_redact_message_logging +from litellm.litellm_core_utils.redact_messages import ( + perform_redaction, + should_redact_message_logging, +) @pytest.fixture(autouse=True) @@ -143,3 +146,53 @@ class TestShouldRedactMessageLogging: litellm_metadata=None, ) assert should_redact_message_logging(details) is True + + +class TestPerformRedaction: + """Unit tests for perform_redaction().""" + + def test_redact_async_complete_streaming_response(self): + """Test that async_complete_streaming_response is properly redacted.""" + response_obj = litellm.ModelResponse( + choices=[ + litellm.Choices( + message=litellm.Message(content="secret content", role="assistant") + ) + ] + ) + + model_call_details = { + "messages": [{"role": "user", "content": "hi"}], + "prompt": "hi", + "input": "hi", + "stream": True, + "async_complete_streaming_response": response_obj, + } + + result = perform_redaction(model_call_details, result=None) + + redacted_response = model_call_details["async_complete_streaming_response"] + assert redacted_response.choices[0].message.content == "redacted-by-litellm" + + def test_redact_complete_streaming_response(self): + """Test that complete_streaming_response is properly redacted.""" + response_obj = litellm.ModelResponse( + choices=[ + litellm.Choices( + message=litellm.Message(content="secret content", role="assistant") + ) + ] + ) + + model_call_details = { + "messages": [{"role": "user", "content": "hi"}], + "prompt": "hi", + "input": "hi", + "stream": True, + "complete_streaming_response": response_obj, + } + + result = perform_redaction(model_call_details, result=None) + + redacted_response = model_call_details["complete_streaming_response"] + assert redacted_response.choices[0].message.content == "redacted-by-litellm"